Lua使树在Roblox上再生

问题描述 投票:0回答:1

所以我用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)```






lua roblox
1个回答
0
投票

这是您可以做的便宜的事情:在开始砍掉分支之前,请对其进行备份。然后,在销毁原件之后,只需等待几秒钟,然后将备份放到位。

所以在您的脚本之后

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属性将备份部分挂接到树部分,从而使其可见。

© www.soinside.com 2019 - 2024. All rights reserved.