Lua 在 Roblox 中让树重新生长

我在 Roblox 中制作了一棵树,可以打破它,然后部分消失。我想在大约一分钟后让它重新生长。这是脚本。我该怎么做?我看到很多人有再生按钮,我想制作一个树,每隔 60 秒就再生一次,我知道你必须做一些等待(60)和一些位置的东西,但在那之后我一无所知

local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Mouse = Plr:GetMouse()
local CouldGetWood = true

function ShowProgress(tree)
 if tree == "Tree" then
  for i = 0,1,.01 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 elseif tree == "HardTree" then
  for i = 0,1,.005 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 end
end

Mouse.Button1Down:connect(function()
 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Tree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.UpperTorso.Position).magnitude < 10 then
   CouldGetWood = false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("Tree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   WC.BG.Visible = false
   CouldGetWood = true
  end
 end

 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "HardTree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.Torso.Position).magnitude < 10 then
   CouldGetWood= false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("HardTree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   WC.BG.Visible = false
   CouldGetWood = true
  end
 end
end)```
点赞
用户1296374
用户1296374

以下是一个便宜的做法:在你开始砍掉树枝之前,先备份它。然后等你摧毁了原先的树枝,只需等几秒钟,再将备份放回原处。

因此,你可以在你的脚本中的代码段里:

if (Wood.Position - Char.UpperTorso.Position).magnitude < 10 then

加入如下代码:

local tree = Mouse.Target.Parent
local backupWood = Wood:clone()

这将创建木材和其子部件的备份。然后,当在函数的结尾摧毁木材后,你可以加入以下代码:

spawn(function()
    wait(60)
    backupWood.Parent = tree
end)

这将产生一个新线程,让你的鼠标处理线程可以继续。在这个线程中,等待60秒钟之后,你将你的备份部件连接到树部件上,即设置Parent属性,使其可见。

2020-04-26 05:03:26