Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What would be the best way to regen a part/model?

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)

2 answers

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

5 comments

0

But then the script doesnt work with the other script

0

Here I edited this for you

0

Try putting a script in the server script service and adding this script to it, I took your scripted and modified it to work. as 1 script

0

Workspace.Handle.Script:16: function arguments expected near ':'

0

Thats your fault why would you put this in a tool?

model=pathtomodelhere
while true do
wait(120)
backup=model:Clone()
model:Destroy()
backup.Parent=game.Workspace.Model(put the path here)
model=backup
end

This discussion is preserved as it was. New answers, comments, and votes are closed.