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

ClickDetector script to push button isn't working? [SOLVED]

I'm pretty sure this is right. This is in a normal script directly inside the button that is supposed to press it for 5 seconds before you can use it again.

button = script.Parent

button.ClickDetector.MouseClick:connect(function()
	if button.CanPress == true then
		button.CanPress = false
		button.Size = Vector3.new(0.29, 1.37, 1.11)
		wait(5)
		button.CanPress = true
		button.Size = Vector3.new(0.57, 1.37, 1.11)
		button.ClickDetector.MaxActivationDistance = 8
	end
end)

1 answer

✓ Accepted answer

It actually would be better if you labeled all your variables, so let's label them;

local B = script.Parent -- button
local CD = B:WaitForChild('ClickDetector') -- the ClickDetector we use waitforchild for it to load in
local CP = B:WaitForChild('CanPress') -- I think this is a bool value

CD.MouseClick:Connect(function()
	if CP.Value == true then
		Button.CanPress = false
	        B.Size = Vector3.new(0.29, 1.37, 1.11)
        	wait(5)
      	 	B.CanPress = true
	        B.Size = Vector3.new(0.57, 1.37, 1.11)
        	CD.MaxActivationDistance = 8
	end
end)

This should work, CanPress has to be a BoolValue because you don't have a variable called CanPress, and the reason it doesn't work is that CanPress is an object, you need the value to change.

If this worked/helped you understand what you did wrong then please accept answer

Good luck developing! Have fun ;)

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