How would I add leaderstats to Carbon Engine?

Me and my friend are new to scripting, and Carbon Engine in general. Because of that, we’re unsure on how to add leaderstats to Engine. There’s a bunch of scripts, some with a bunch of code in one line. I have the leaderstats already made, I just need to connect the Carbon Engine kills to that.

Kills leaderstat part:

        local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = newPlayer.leaderstats
	kills.Value = 0
1 Like

I’m not exactly sure what you mean by “connecting the leaderstats” to your engine but I will just assume that you actually want to see the Kill count go up when killing another entity.

Whereever you damage the humanoid in your engine you want to tag the enemy hit. Like this:

local function tagHum(hum, plr)
    local tag = Instance.new("ObjectValue")
    tag.Name = "creator"
    tag.Value = plr
    tag.Parent = hum
    game:GetService("Debris"):AddItem(tag, 2)
end

-- use the tagHum function BEFORE you damage the enemies humanoid itself
humanoid = enemy.Humanoid -- humanoid of enemy
player = -- player instance that is doing the damage
tagHum(humanoid, player)
-- damage the humanoid and continue your script

Now the enemy is tagged. You now want to put a Script instance into the enemies character:

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

local function dead()
    local tag = hum:FindFirstChild("creator")
    if tag then
        if tag.Value then
            local leaderstats = tag.Value:FindFirstChild("leaderstats")
            if leaderstats then
                local kills = leaderstats:FindFirstChild("Kills")
                if kills then
                    kills.Value += 1
                end
            end
        end
    end
end

hum.Died:Connect(dead)

Remember that this works on every entity containing a humanoidy. I don’t know what your engine is but if you only want to go up when a player is killed you would need some extra code.

This basically is a tagging system, you can find it everywhere, you only have to find the line where carbon engine damages the humanoid. I’m not sure maybe it already does have a tagging system

2 Likes

So like, I want it to where say I kill someone, my kill leaderstat would go up.

If the scripts you provided for it are about that, where should I put them?

1 Like

Im not sure, is carbon engine a gun engine? If so, you will look in which line of code the gun damages the enemy that was hit by a shot. Before they damage the enemy you will have to put the first script.

The second script will be placed into the enemy that is supposed to be killed. If you dont want to put every script manually you can automate that process by looping through every entity ingame and copying the second script into their character.

The thing is, the code is all in one line.

I wanna thank you for helping me out. The script ended up working, I just had to mess around with a few things. I hope you have happy holidays!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.