So I made this kill counter which appears in the leaderstats, and for some reason it doesn’t work! Whenever I kill someone, my kills stay 0, and everyone else’s kills are just -. does anyone have a fix for this?
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Value = 0
kills.Parent = leaderstats
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Kills.Value = leaderstats.Kills.Value + 1
Obviously, because there is no value “creator” creating in them. You have to add an objectvalue named creator to them, in order to this to work…
So I added an objectivevalue named “Creator”, but it still doesn’t work. Do I have to add this to the workspace or somewhere else?
So I tested this script in a random game of mine just to see if it works before adding it into the current game, and for some reason it works. But, when I copy everything onto my current game, even the sword, it doesn’t work.
Your random game probably consisted of using a different leaderboard system, can you check if the sword will give the Target a
creator ObjectValue when hit?
No it does not give the creator any ObjectValues.
I don’t think this will work as you intend it to. It would be best to add a part in the sword script where it causes damage to things.
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum.Health > 0 then
if damage >= hum.Health then -- It would be best to have a variable to store the damage amount.
-- You can add some function to handle changing kills here as this would detect a death
else if damage < hum.Health then
I just had an idea. So you know how at the beginning of the script it created a new folder? I have another leaderstat, which is wins. If there are two folders within leaderstats, does one break?