debounce = false workspace.Island.Teleport.IslandTP1.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and debounce == false then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local GUI = plr.PlayerGui.ScreenGui:FindFirstChild("Frame") debounce = true if GUI.Visible == false then GUI.Visible = true wait(1) debounce = false end end end)
I touch the part it shows me the gui but after I make my gui invisible it doesnt work unless I reset.
So for your if statement you are not putting an else
. If statements can have more than one condition or statements built inside of it. The reason why it works once is because your saying if the gui is false then set to true.
So your script fixed would be:
debounce = false workspace.Island.Teleport.IslandTP1.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and debounce == false then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local GUI = plr.PlayerGui.ScreenGui:FindFirstChild("Frame") debounce = true if GUI.Visible == false then GUI.Visible = true else GUI.Visible = false end wait(1) debounce = false end end)
If it doesn't work leave a comment on my question with the output error in it and I can try to solve it.
If you want here is a link to the roblox wiki on if statements: https://developer.roblox.com/en-us/articles/Conditional-Statements-in-Lua
You can ask clarification anytime
It happens when your GUI is visible and "Touched" event occurs (may happen when character moves on the teleport platform). In this case the debounce flag can't reset. Just put the debounce = false
line outside of the if block. If you're trying to sync it with the other script using a wait function - don't do it. It's absolutely inreliable.
debounce = false workspace.Island.Teleport.IslandTP1.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and debounce == false then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local GUI = plr.PlayerGui.ScreenGui:FindFirstChild("Frame") debounce = true if GUI.Visible == false then GUI.Visible = true wait(1) end debounce = false end end)