Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How To Make A System Where If You Kill Someone The IntValue Goes Up By One?

Asked by 6 years ago

So the question is kind of self explanatory. I thought my script should work, but it doesn't. Here it is:

game.Players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "leaderstats"
    local currency1 = Instance.new("IntValue",folder)
    currency1.Name = "Kills"
    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
                    -- Here tag.Value is the player who killed us, so find their leaderstats
                    local killersLeaderstats = tag.Value:FindFirstChild("leaderstats")
                    if killersLeaderstats then
                        -- Award the Kills to the player that killed us
                        killersLeaderstats.Kills.Value = killersLeaderstats.Kills.Value + 1
                    end
                end
            end
        end)
    end)
end)

Any idea what the problem is. Hope you can help thanks!

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

Creator ObjectValues are an ancient and badly designed solution for knockout leaderboards. Instead, modify your weapons. When the weapon does damage to a player, check if the player's new health is <= 0. If so, the player who attacked with the weapon killed the dead player, and you can award them one kill.

Additionally, RBXScriptSignal:connect() is deprecated, you should prefer RBXScriptSignal:Connect().

Ad

Answer this question