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

Why is this regen script not working?

Asked by 9 years ago

The script is supposed to regen a model after a certain amount of time. However, the script doesn't work at all. Output didn't give me anything.

Can someone please help me?

Here's the script:

local Playing = game.ServerScriptService.MainGame:WaitForChild("Playing")
local children = script.Parent:GetChildren()
local Tanks = children:clone()

while wait(10) do
    if Playing.Value == true then
        children:remove()
        wait(0.1)
        Tanks.Parent = script.Parent
    end
end
1
its because you're removing the script. HungryJaffer 1246 — 9y
0
He's right, and i dont understand why you're using a getchildren, just clone the model :l Codebot 85 — 9y
0
Actually, I think scripts continue to run after being destroyed. The script above doesn't even destroy itself. IDidMakeThat 1135 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

The problem is probably that you are trying to call remove() on children. children is a table of Instances, not an Instance itself. To remove all Instances in children, use a generic for loop, like so:

local Playing = game.ServerScriptService.MainGame:WaitForChild("Playing")
local children = script.Parent:GetChildren()
local Tanks = children:clone()

while wait(10) do
    if Playing.Value == true then
        for i, v in ipairs(children) do
        v:Destroy() -- Note that remove() is deprecated.
    end
        wait(0.1)
        Tanks.Parent = script.Parent
    end
end

Also, I believe you should put the main game script somewhere like the workspace, since I don't think scripts in the ServerScriptService can interact with the game world, and that is probably the problem you're having in the first place.

Ad

Answer this question