So I made an exp/zombies killed script and I added them into zombies but for some reason the script gives more exp/zombies killed than 1 ; it gives like 3 exp and 3 zombies killed but I need it to give 1 exp and 1 zombies killed. I’ve tried debounce and other things but it still doesn’t seem to work. It doesn’t print any errors either.
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Humanoid.Died:Connect(function()
if script.Parent.Humanoid.Health <= 0 then
if debounce == true then
debounce = false
player:FindFirstChild("EXP").Value = player:FindFirstChild("EXP").Value + 1
player:FindFirstChild("Zombies Killed").Value = player:FindFirstChild("Zombies Killed").Value + 1
wait(0.5)
debounce = true
end
end
end)
end)
You’re using script.Parent.Humanoid, which means the script is in the Character. So it might mean you’re duplicating the script, so you might have multiple Died events connected to the same player.
My suggestion?
Keep the script in one place, swap script.Parent.Humanoid to player.Character.Humanoid
Quick, but very helpful tip
You can actually swap player:FindFirstChild("EXP").Value = player:FindFirstChild("EXP").Value + 1
for player:FindFirstChild("EXP").Value += 1
+= means the original value + the value ahead
These also work, -=, *= and /=, each one is self explanatory
the script is inside a zombie, not the player, i added the script inside the zombie and when the zombie dies, it gives exp and +1 zombie killed stat (the game is solo)
It’s being added 3 EXP and Zombies Killed for every zombie you kill or is it changing whenever you kill a zombie?
Also, you don’t really need to use if script.Parent.Humanoid.Health <= 0 then
Since you already have a connection for Humanoid.Died which fires when the Humanoid dies, usually when Humanoid.Health reaches 0.
the first or second zombie i kill gives 3 and then one other zombie after it gives 3 as well but then after like some few kills it changes back to 1 exp per zombie
also i added that if then statement because nothing worked so…
A hacky alternative to fix the leaderstats issue would have a connection that fires everytime EXP and Zombie Killed changes, you would have a variable that stores the leaderstat before it changed and add +1 to that variable everytime it changes, then set the stat as that variable.
Keep in mind this doesn’t directly fix that issue, It just keeps manually fixing the leaderstat. Since I don’t have context of how your game works then It might not work.
You can also show the script that duplicates the zombies if you’d like to.