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)
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.