Hello Developers!
I have a game with leaderstats of kill for money
But I have a problem, When someone kill me I get the money and not him
I need your help by giving me a feedback on the leaderstats script
Check the script and tell me what the problem is.
Tell me what needs to be changed in the script for it to work properly.
The script:
game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency1 = Instance.new("IntValue",folder)
currency1.Name = "Money"
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 10 --This is the reward after the player died.
end
end
end)
end)
end)
Wouldn’t it be a better idea to find the player through the ‘creator’ tag? If I remember correctly, you should store the name of the player in the ‘creator’ value so you can determine the player. From there, navigate to that player’s ‘Money’ ValueObject and from there, you can change it. In your script, you aren’t showing that you’re actually retrieving the player from the creator tag, so that’s why I’m fairly confused how you’re determining who the killer was.