What would be the best way to regen a part after a while?
The code I have for one part is this, but I cant think of a way to regen it after about 120 seconds, or so.
local Apple = script.Parent local Clicker = Apple.ClickDetector local Worth = 1 Clicker.MouseClick:connect(function(Player) local Money = Player:FindFirstChild("Money") if Money then Money.Value = Money.Value + Worth Apple:Destroy() end end)
Make sure this script isn't in the regen brick, cause if it is it will delete the brick and the script so put this is the ServerScriptService or in the Workspace and change the names of delete to the name of the brick and make sure its pointing to the right directory
local Apple = game.Workspace:WaitForChild("Apple") -- What we will delete local Clicker = Apple:WaitForChild("ClickDetector") local Worth = 1 local regen = delete:Clone() -- What will be put into the workspace(clone of it) local duration = 120 -- The duration we wait game.Workspace.ChildAdded:connect(function(Child) if Child.Name == "Apple" then Apple = Child Clicker = Child:WaitForChild("ClickDetector") Clicker.MouseClick:connect(function(Player) local Money = Player:FindFirstChild("Money") if Money ~= nil and Apple ~= nil then Money.Value = Money.Value + Worth game:GetService:AddItem(Apple, 0) else print("Money Or Apple Doesn't Exist") end end) else end end) while wait(duration) do if Apple ~= nil then game:GetService("Debris"):AddItem(Apple, 0) -- Deletes it local clone = regen:Clone() -- clones what we regen clone.Parent = game.Workspace clone:MakeJoints() -- puts into workspace while making joints Apple = clone -- makes sure the delete variable isn't nil so it will continuously work. else end end
model=pathtomodelhere while true do wait(120) backup=model:Clone() model:Destroy() backup.Parent=game.Workspace.Model(put the path here) model=backup end