Essentially, while players are in contact with a certain uncancollided brick (its swamp water if you were curious), they are supposed to have a GUI show up on their screen to act as fog/swampgas. However, while in contact with the water, the GUI comes up but doesn't disappear when I leave the brick. Before adding a debounce (which I probably did incorrectly), the GUI would just glitch in and out as I walked through the brick (hence why I thought a debounce would fix it). Can anyone help me out with why this isn't working properly? Thanks so much in advance.
local Players = game:GetService("Players")
debounce = true
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum ~= nil and debounce == true then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
debounce = false
player.PlayerGui.SwampGas.Enabled = true
wait(1)
debounce = true
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum ~= nil then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
player.PlayerGui.SwampGas.Enabled = false
end
end
end)

3 comments
Why is a server script handling GUIs? The server shouldn't be handling interface or input or be knowing about it.
It's just a script inside of a brick that accesses the player gui of those who touch it. Is that so wrong?
Use remote events and enable a GUI in the players PlayerGui