Give Exp script giving more exp than amount?

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

Happy coding

3 Likes

Is script.Parent referring to the zombie?

yeah script.parent refers to the zombie

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)

Can you show us the duplication script?

duplication script? this script is the only give exp script in the zombie

oh wait, do you mean a script that duplicates the zombies?

how many players are playing when you test game?

there is one player per server since its going to be a story mode type of game

1 Like

i think your code have duplication thing or idk something like this happend to me too
my models cloned 2 times

i just duplicate the zombies in workspace, not by a script because whenever i try to clone them, they stop animating for some reason

1 Like

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.

1 Like

mmm… i think your problem is from your main game maybe

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…

so do you know what I should do? i kinda need it a lot

Sorry, but I honestly cannot see what’s causing this issue, It’s probably something else that is causing that, which may be not this specific script.

Make sure to follow what @AvionicScript said also.

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.

There is no duplication script for the zombies, I just made a bunch of models in workspace and added them into the game since it will be solo