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

"If x == 5 then" is not working? (Fixed)

x = 0
bu = game.Workspace.Button1
bu.ClickDetector.MouseClick:Connect(function()
	x = x + 1
end)

buy1 = script.Parent
buy1.Touched:Connect(function()
	if x == 5 then
		buttony = game.Lighting.Button2:Clone()
		buttony.Parent = game.Workspace
	end
end)


The script doesn't show any errors but it's not working. I tried figuring it out and I think the problem is in the "If x == 5 then".

11 comments

0

have you tried changing it to if x ==5 then do, or if x==5 do?

0

Tried that, doesn't work

0

hmm

0

This isn't an answer to your specific problem, but I think you should work on the presentation of your code: variable names are random/abstract; It's inconsistent (Connect/connect the latter is deprecated); no logical layout - it's generally difficult to read. I'd recommend addressing this if you want to get help easier and if you want to progress further in the future. Good luck!

0

does the touch event run at all?

0

can you print out: print(x, x==5) whenever the player touches the button?

0

The touch event works.

0

The "If x == 5 then" doesn't work. When I remove the "if x == 5" it does work

0

Coppied your script and it worked perfectly

0

Really? Let me show you the game I have the script in https://www.roblox.com/games/3194043675/Game

0

Try printing the X variable before the if line, see if the value is actually five.

1 answer

✓ Accepted answer

I found the problem, when I was pressing the button. It has to be exactly 5 not >= 5. I pressed the button more than five and making it not work.

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