Hello! I am making a tutorial game, and at the start of making it, this script would work perfectly, now It sadly doesn’t, I’ve done some twitching, but it still doesn’t work.
There are no errors showing up in the output.
I checked, and the model is anchored, some can collide off.
local debounce = false
script.Parent.Touched:connect(function(hit)
if debounce == false then
debounce = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
game.Workspace.Welcome:Play()
print('Audio has played')
player.PlayerGui.Welcome.Enabled = true
print('Gui has true')
wait(3.2)
player.PlayerGui.Welcome.Enabled = false
print('Gui has false')
wait(3600) --The wait is optional
debounce = false
end
end)```
1 Like
The problem is in your use of debounce. You should check for player and debounce in the same line,
if player and not debounce then
-- do stuff
end
What’s happening here is if debounce is false, you make it true. Then if player doesn’t exist (which can happen very often), you exit the Touched event, never turning debounce false again. Next time the Touched event is fired, debounce is still true and the rest doesn’t run.
Fixed script
local debounce = false
script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not debounce then
debounce = true
game.Workspace.Welcome:Play()
print('Audio has played')
player.PlayerGui.Welcome.Enabled = true
print('Gui has true')
wait(3.2)
player.PlayerGui.Welcome.Enabled = false
print('Gui has false')
wait(3600) --The wait is optional
debounce = false
end
end)
1 Like
Thank you so much! You saved my game