Somehow it doesnt give += 1 it gives way more then that

hey guys i am trying to make stats on plr kill
i am using the humanoid.Died function for it but it doesnt give the stats i want it to give
this is the script

						Humanoid.Died:connect(function()
							leaderstats.Credit.Value += 10
							leaderstats1.XP.Value += 100
						end)

it always gives a random number that is like 10 times 100
i want this fixed but i cant seem to figure out how :confused:
the best thing would be detecting if the player took dmg and if the player died after the dmg.
please help :confused:

(What the script does)

the script has a hit function, when the hit function fires it deletes the part that hit after 0,4 secs (0,4 secs cuz i want it to hit other ppl too)
it might have to do with the 0,4 seconds but i dont think it does since when the player dies after the 0,4 secs it still gives way to much stats

Could you please show your entire code?
Because I’ve tested it here:

game.Players.PlayerAdded:Connect(function(Player)
	local ls = Instance.new("Folder")
	ls.Name = "leaderstats"
	ls.Parent = Player
	
	local Credit = Instance.new("IntValue")
	Credit.Name = "Credit"
	Credit.Parent = ls
	
	local XP = Instance.new("IntValue")
	XP.Name = "XP"
	XP.Parent = ls
	
	Player.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:connect(function()
			Credit.Value += 10
			XP.Value += 100
		end)
	end)
end)

And it worked [if the purpose is to give the player who dies the rewards].
if you want to award the killer the rewards, usually when a player is being hit by someone, a value named ‘creator’ is created inside the humanoid of the player whom being hit, so you could get that value’s value and reward the killer [will only work if the killer was mentioned/related to the ‘victim’

The code as it is shown here should work fine. Without the rest of the code the exact answer won’t be possible to pinpoint. However one thing that might be causing this is if that died connection is being created more than once. There are a lot of potential reasons why that could happen.

You could try player.CharacterRemoving instead

player.CharacterRemoving:connect(function()
	leaderstats.Credit.Value += 10
	leaderstats1.XP.Value += 100
end)

i want to give it to theplayer who killed the other player

how could i fix this?
kjkninoiompooop 30 txt

Send the whole script. You can’t post a snippet of code and expect us to debug the issue. My guess is you’re connecting the .Died connection multiple times (without disconnecting) either in a loop or another connection. When the player dies they all fire at once making it seem like it’s giving 10x the amount.

do you know how i could disconnect the function?

If you want to change a value , you can write

Value = Value + 1

It will work, trust me!
Its more accurate and cant error

[If i solved your problem please mark this as solution!]

1 Like

This is fundamentally the same as += and won’t fix anything

2 Likes

You can technically disconnect the function

local diedEvent = humanoid.Died:Connect(function()
    print("Humanoid died")
end
diedEvent:Disconnect() --This is impractical here, but disconnects the event

However, it’s worth noting that this is probably addressing the symptom and not the actual problem. Ideally you’d only register the event once getting rid of the need to disconnect. Since you haven’t stated what the context for registering the .died event is, this is about as far as anyone can really help before it’s purely guess work.

If you really don’t want to provide the rest of your code due to sensitive coding, what I suggest you to do is to add a print function and see if this snippet of a code is the reason why players are getting more credits than they’re supposed to, or how often it gives them credits/xp’s. This way you can check if your other scripts is the culprit or if, like everyone here is saying, it’s being recalled multiple times.

1 Like

Humanoid.Died has a habit of being triggered more than once per death, so use Humanoid.Died:Once rather than Humanoid.Died:Connect

1 Like

Try it before telling wrong stuff

1 Like

this didnt really solve it but it did optimize it so ty :smiley:

Please send the whole code, this would greatly help us in solving problem.

huh what is that i never heard of that huh

1 Like

Ignoring the bruh moment that is, my link didn’t properly lead to what I was trying to get it to lead to.
Operators | Documentation - Roblox Creator Hub This is what I meant


Just use this.

1 Like