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

Help I don't know how to fix this regen script?

I what it to have some time between each regen. At the moment you cane keep regening every sec. Can some please help me to fix this?


local box = script.Parent


local debounce = false

local everything = {model}
local names = {model}

local children = game.Workspace:children()
for i=1,#children do
	if (children[i].Name == "Bus1") then 
		table.insert(everything, children[i]:clone())
		table.insert(names, children[i].Name)
	end
end


function regen()
	for i=1,#everything do
		new_thing = everything[i]:clone()
		new_thing.Parent = game.Workspace
		new_thing:makeJoints()
	end
end

function onTouched()		
		script.Parent.BrickColor = BrickColor.new(26)

		regen()
		wait(60)


		script.Parent.BrickColor = BrickColor.new(104)


		debounce = false
end

 script.Parent.ClickDetector.MouseClick:connect(onTouched)

2 answers

✓ Accepted answer

Need to check if debounce is activated or not.

local box = script.Parent


local debounce = false

local everything = {model}
local names = {model}

local children = game.Workspace:children()
for i=1,#children do
    if (children[i].Name == "Bus1") then 
        table.insert(everything, children[i]:clone())
        table.insert(names, children[i].Name)
    end
end


function regen()
    for i=1,#everything do
        new_thing = everything[i]:clone()
        new_thing.Parent = game.Workspace
        new_thing:makeJoints()
    end
end

function onTouched()
		if not debounce then debounce = true
        script.Parent.BrickColor = BrickColor.new(26)

        regen()
        wait(60)


        script.Parent.BrickColor = BrickColor.new(104)


        debounce = false
end
end

 script.Parent.ClickDetector.MouseClick:connect(onTouched)


1 comment

0

thanks that worked

I was about to fix it, but then I saw that Dummie already fixed it correctly. :I

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