It works fine the first few times I use it but then breaks. Anyone have any idea why this could be happening? any help will be appreciated
debounce = true script.Parent.Touched:connect(function(hit) if debounce == false then return end if debounce == true then debounce = false local hum = hit.Parent:FindFirstChild("Humanoid") if hum ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local treasure = player.leaderstats.Treasure if treasure.Value == 50 or treasure.Value > 50 then treasure.Value = treasure.Value - 50 local ship = game.ReplicatedStorage.RedShips.Ship1:Clone() ship.Parent = game.Workspace.Ships ship:MakeJoints() script.Parent.Parent.gp.Transparency = 1 script.Parent.Parent.gp.CanCollide = false wait(6) script.Parent.Parent.gp.Transparency = 0 script.Parent.Parent.gp.CanCollide = true debounce = true else if debounce == false then debounce = true end end end end end)
edit: Incase anyone wants to know how I solved it I made the script find the humanoid first so a random brick would break it new script:
debounce = true script.Parent.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum ~= nil then if debounce == false then return end if debounce == true then debounce = false local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local treasure = player.leaderstats.Treasure if treasure then if treasure.Value == 50 or treasure.Value > 50 then treasure.Value = treasure.Value - 50 local ship = game.ReplicatedStorage.RedShips.Ship1:Clone() ship.Parent = game.Workspace.Ships ship:MakeJoints() script.Parent.Parent.gp.Transparency = 1 script.Parent.Parent.gp.CanCollide = false wait(6) script.Parent.Parent.gp.Transparency = 0 script.Parent.Parent.gp.CanCollide = true debounce = true else if debounce == false then debounce = true end end end end end end end)