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

How do I get this regen button that limits regens to work?

In the script, the script obtains a copy of the model to be regened, and then remove the model. The script is also supposed to detect if an outside variable is true or false, and the script will only work if the variable is false. However, the script is not working period, and I have no idea why, as output gave me nothing.

Can someone please help me?

Here's the script:

local Detect = script.Parent.Parent.Parent:WaitForChild("CoolDown")
local location = script.Parent.Parent.Parent
local regen = script.Parent.Parent
local save = regen:clone()
local CanClick = false
script.Parent.Parent.Heli:remove()

while wait do
	if Detect.Value == false then
		CanClick = true
	elseif Detect.Value == true then
		CanClick = false
		script.Parent.BrickColor = BrickColor.new("Black")
	end
	wait(0.01)
end

function onClicked()
	if CanClick == true then
		regen:remove()
		local back = save:clone()
		back.Parent = location
		back:MakeJoints()
		Detect.Value = true
	end
end 

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

1 answer

I believe the issue here stems from the while loop. You said "while wait do" without giving it a wait time! The word "wait" isn't a variable in the script, so the script is confused. While you can fix this by giving it a wait time, it is actually much more efficient to use the Changed event to check if Detect's value is changed.

Detect.Changed:connect(function()
	if Detect.Value == false then
		CanClick = true
	elseif Detect.Value == true then
		CanClick = false
		script.Parent.BrickColor = BrickColor.new("Black")
	end
end)

Also, replace all uses of Remove() with Destroy(). Remove() is deprecated and Destroy() is much more efficient.

2 comments

0

It's still not working, and output is still not giving me anything to work with

0

Hmm, CanClick starts out as false. That might be the issue. Can you tell me if there's a script that changes Detect's value?

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