So, what I am trying to achieve is, you step on a part called “Trigger” and then it opens up a GUI, then you step off it goes invisible
I looked for a tutorial and found one who had pretty much the exact same script.
But my issue is, it doesnt close
Script
local Player = game:GetService("Players")
local debounce = false
function Touched(hit)
if debounce == false then
local player = Player:GetPlayerFromCharacter(hit.Parent)
player.PlayerGui.Gamepass.Enabled = true
elseif debounce == true then
local player = Player:GetPlayerFromCharacter(hit.Parent)
player.PlayerGui.Gamepass.Enabled = false
end
end
script.Parent.Touched:Connect(Touched)
I dont get anything in the output
I’m pretty sure it’s an issue with the debounce, and honestly, debounces just confuse no matter how much I read the api and watch tutorials
And I only want it Client sided, not server sided, so im guessing I wouldnt need Remove Events.
Hey there. So… Enabled is not what you think. The property you are actually looking to change, is the Visbility property of the GUIObject, keep in mind that only things WITHIN a gui have this property, not the GUI itself. The solution is to create a frame inside your GUI that is size 1,0,1,0 and to make that Visible = true or false
There is another function with which you can determine if the player has stopped touching the selected Instance. It’s called TouchEnded. I also have realised that you don’t change the value of variable called “debounce” inside of your script, make sure to fix this because that might be the problem it doesn’t work.
Here is an example of your script with TouchEnded:
local Player = game:GetService("Players")
local debounce = false
function Touched(hit)
if debounce == false then
local player = Player:GetPlayerFromCharacter(hit.Parent)
player.PlayerGui.Gamepass.Enabled = true
debounce = true
end
end
function TouchEnded(hit)
if debounce == true then
local player = Player:GetPlayerFromCharacter(hit.Parent)
player.PlayerGui.Gamepass.Enabled = false
debounce = false
end
end
script.Parent.Touched:Connect(Touched)
script.Parent.TouchEnded:Connect(TouchEnded)