Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago
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".

0
have you tried changing it to if x ==5 then do, or if x==5 do? Sadwowow21 57 — 4y
0
Tried that, doesn't work User#32567 0 — 4y
0
hmm Sadwowow21 57 — 4y
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! turtle2004 167 — 4y
View all comments (7 more)
0
does the touch event run at all? royaltoe 5144 — 4y
0
can you print out: print(x, x==5) whenever the player touches the button? royaltoe 5144 — 4y
0
The touch event works. User#32567 0 — 4y
0
The "If x == 5 then" doesn't work. When I remove the "if x == 5" it does work User#32567 0 — 4y
0
Coppied your script and it worked perfectly tjtorin 172 — 4y
0
Really? Let me show you the game I have the script in https://www.roblox.com/games/3194043675/Game User#32567 0 — 4y
0
Try printing the X variable before the if line, see if the value is actually five. EmK530 143 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question