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
it always gives a random number that is like 10 times 100
i want this fixed but i cant seem to figure out how
the best thing would be detecting if the player took dmg and if the player died after the dmg.
please help
(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.
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.
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.