Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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().

This discussion is preserved as it was. New answers, comments, and votes are closed.