While testing the game for bugs, this script’s debounce remains as false if the player leaves the game right after hitting the part.
Script |
local Spawns = game.Workspace.Lobby.Map:FindFirstChild("Spawns"):GetChildren()
local Teleports = game.Workspace.Stages:FindFirstChild("Teleports")
local Debounce = false
script.Parent.Touched:Connect(function(Hit)
if Debounce then return end
Debounce = true
local PlayerStats = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Hit.Parent:FindFirstChild("Humanoid") then
local Player = Hit.Parent
Player.Torso.CFrame = Spawns[math.random(1, #Spawns)].CFrame
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 90
if PlayerStats.DoubleXP.Value == true then
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 90
end
wait(1)
Debounce = false
end
end)
While attempting to debug it no errors have shown up in the output and I have also tried printing stuff in the output after each line is executed and it works fine. Though for example, say I left the game right when I hit the part, then the debounce remains false.
You could try setting the Debounce outside the conditional check perhaps?
local Spawns = game.Workspace.Lobby.Map:FindFirstChild("Spawns"):GetChildren()
local Teleports = game.Workspace.Stages:FindFirstChild("Teleports")
local Debounce = false
script.Parent.Touched:Connect(function(Hit)
if Debounce then return end
Debounce = true
local PlayerStats = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Hit.Parent:FindFirstChild("Humanoid") then
local Player = Hit.Parent
Player.Torso.CFrame = Spawns[math.random(1, #Spawns)].CFrame
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 90
if PlayerStats.DoubleXP.Value == true then
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 90
end
end
wait(1)
Debounce = false
end)