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

Why is this regen script not working?

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

3 comments

1

its because you're removing the script.

0

He's right, and i dont understand why you're using a getchildren, just clone the model :l

0

Actually, I think scripts continue to run after being destroyed. The script above doesn't even destroy itself.

1 answer

✓ Accepted answer

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.

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