Hi, When making a single button that alternates between two options when you click it, a problem arises. The button is supposed to teleport you to one brick, but, when the second-long debounce ends, it teleports you to the other brick, as though you clicked on it again. I'm not sure what's causing this. Any ideas?
01 | player = game.Players.LocalPlayer |
02 | button = script.Parent |
03 | local debounce = false |
04 | image = script.Parent.Parent.ImageButton.Image |
05 |
06 | function helpme() |
07 | if not debounce then |
08 | if image = = "rbxassetid://2730594257" then |
09 | debounce = true |
10 | image = "rbxassetid://2730605530" |
11 | local LowerTorso = player.Character.LowerTorso |
12 | LowerTorso.CFrame = game.Workspace.telepart 4. CFrame |
13 | wait( 1 ) |
14 | debounce = false |
15 | end |
I Think it is because you forgot the else, So what I think was happening is that the game was checking the first If statement then it waited 1 second and checked the second one, and it executes both statements each click instead of executing 1 each time you click. (Also I Marked The Place I Added An Else)
Try This:
01 | player = game.Players.LocalPlayer |
02 | button = script.Parent |
03 | local debounce = false |
04 | image = script.Parent.Parent.ImageButton.Image |
05 |
06 | function helpme() |
07 | if not debounce then |
08 | if image = = "rbxassetid://2730594257" then |
09 | debounce = true |
10 | image = "rbxassetid://2730605530" |
11 | local LowerTorso = player.Character.LowerTorso |
12 | LowerTorso.CFrame = game.Workspace.telepart 4. CFrame |
13 | wait( 1 ) |
14 | debounce = false |
15 | else if image = = "rbxassetid://2730605530" then ------------------------------------------- I added an else here so then you need to click a second time to check what image it is |
(I Havent Tested It So Sorry If It Doesn't Work)