debounce = false function onTouched(part) if debounce == false then debounce = true local h = part.Parent:findFirstChild("Humanoid") if h ~= nil then local Player = game.Players:GetPlayerFromCharacter(part.Parent) Player.leaderstats.Score.Value = Player.leaderstats.Score.Value - 1 game.Players:FindFirstChild(Player.leaderstats.LastHit).leaderstats.Score.Value = game.Players:FindFirstChild(Player.leaderstats.LastHit).leaderstats.Score.Value+1 Player:LoadCharacter() debounce = false end end end script.Parent.Touched:Connect(onTouched)
on line 11, apparently Player doesnt exist, but i tried using prints and it does.
This should work for you.
local debounce = false script.Parent.Touched:Connect(function(hit) if debounce == false then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local stat1 = player:WaitForChild("leaderstats").Score stat1.Value = stat1.Value -1 local stat2 = player:WaitForChild("leaderstats").LastHit stat2.Value = stat2.Value +1 end end wait(5) debounce = false end)
Please accept my answer if this helped! Thanks
Edit: forgot the end, wrote this from scratch
Here is a script you can try.
debounce = false script.Parent.Touched:connect(function(Obj) if Obj.Parent:FindFirstChild("Humanoid") ~= nil then if debounce == false then debounce = true local Player = game.Players:GetPlayerFromCharacter(Obj.Parent) Player.leaderstats.Score.Value = Player.leaderstats.Score.Value - 1 Player.leaderstats.LastHit.leaderstats.Score.Value = Player.leaderstats.LastHit.leaderstats.Score.Value + 1 Player:LoadCharacter() debounce = false end end end)
If it works accept my answer. Thanks!