Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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
0
But then the script doesnt work with the other script KennySfromTitan 106 — 9y
0
Here I edited this for you DevScripting 92 — 9y
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 DevScripting 92 — 9y
0
Workspace.Handle.Script:16: function arguments expected near ':' KennySfromTitan 106 — 9y
0
Thats your fault why would you put this in a tool? DevScripting 92 — 9y
Ad
Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
9 years ago
model=pathtomodelhere
while true do
wait(120)
backup=model:Clone()
model:Destroy()
backup.Parent=game.Workspace.Model(put the path here)
model=backup
end

Answer this question