How would I go on creating a leaderstats system which on kill gives cash to the player?

Hello, I’m a fairly new scripter and I’m trying to create a sword fight system in which any time you kill someone, you get cash. I’ve already set up a leader stats system but I’m unsure on how I’d go on making one. I’ve looked on YouTube for tutorials and they don’t work, and I’ve checked the dev forums as well.

1 Like

I don’t know what you searched up on youtube but when I searched up “get money when you kill roblox” a bunch of videos came up…

Example:

Tried that video already, doesn’t work for me.

Do you have any tools that deal damage to players? if so can you paste the part that deals the damage to other players please.

Do you mean the name of them?
char limit char limit

No just the part that deals damage in the script.
You can find it by searching TakeDamage in the script.

Yeah I know, but the name of those particular parts?

They’re usually just TakeDamage() here’s an example

if Target:FindFirstChildOfClass("Humanoid") ~= nil then 
Target:FindFirstChildOfClass("Humanoid"):TakeDamage(math.floor(Damage))
-- Target is the player hit and they took damage accordingly.

Ah okay, I thought you literally meant a part.

Also, I forgot to mention that I’m just helping my friend, so I didn’t make the script for the swords.

local Tool = script.Parent --Finds Tool
local Handle = Tool:WaitForChild("Handle") --Waits for child "Handle"
local Model = Tool:WaitForChild("Model") --Waits for child "Model"

local Slash = script:WaitForChild("Slash") --Waits for child "Slash"
local Debounce = false --I don't know this one
local PlayersHit = {} --When player hits someone

--Adds Weld
--Weld is something you add in a tool that will not break

for i, Parts in pairs(Model:GetChildren()) do --To get every child in Tools

    if Parts:IsA("BasePart") then --Check if children models is BasePart

        local Weld = Instance.new("WeldConstraint") --Created new Variable called "Weld"
        Weld.Part0 = Parts --Welds parts
        Weld.Part1 = Handle --Welds Handle
        Weld.Parent = Parts --Welds parts
    end
end

--Animate

Tool.Activated:Connect(function() --Activates event

    if Debounce == false then
        Debounce = true --If Debounce is false then it will change to true

        local Humanoid = Tool.Parent:WaitForChild("Humanoid") --Making Variable to "Humanoid", would be character if it's equipped
        local AnimTrack = Humanoid:LoadAnimation(Slash) --When clicked played animation

        AnimTrack:Play() --Play function for AnimTrack
        wait(0.1) --Wait 1 second
        Debounce = false --Activate to false after Animation played
    end
end)


--Damage

Handle.Touched:Connect(function(Hit) --When player clicked

    if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= Tool.Parent then

        if Debounce == true and PlayersHit[Hit.Parent] == nil then

            Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(65) --You can change to whatever damage you want

            PlayersHit[Hit.Parent] = true
            wait(1)
            PlayersHit[Hit.Parent] = nil
        end
    end
end)

Try this:

local Tool = script.Parent --Finds Tool
local Handle = Tool:WaitForChild("Handle") --Waits for child "Handle"
local Model = Tool:WaitForChild("Model") --Waits for child "Model"

local Slash = script:WaitForChild("Slash") --Waits for child "Slash"
local Debounce = false --I don't know this one
local PlayersHit = {} --When player hits someone

--Adds Weld
--Weld is something you add in a tool that will not break

for i, Parts in pairs(Model:GetChildren()) do --To get every child in Tools

    if Parts:IsA("BasePart") then --Check if children models is BasePart

        local Weld = Instance.new("WeldConstraint") --Created new Variable called "Weld"
        Weld.Part0 = Parts --Welds parts
        Weld.Part1 = Handle --Welds Handle
        Weld.Parent = Parts --Welds parts
    end
end

--Animate

Tool.Activated:Connect(function() --Activates event

    if Debounce == false then
        Debounce = true --If Debounce is false then it will change to true

        local Humanoid = Tool.Parent:WaitForChild("Humanoid") --Making Variable to "Humanoid", would be character if it's equipped
        local AnimTrack = Humanoid:LoadAnimation(Slash) --When clicked played animation

        AnimTrack:Play() --Play function for AnimTrack
        wait(0.1) --Wait 1 second
        Debounce = false --Activate to false after Animation played
    end
end)


--Damage

Handle.Touched:Connect(function(Hit) --When player clicked

    if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= Tool.Parent then
           local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
        if Debounce == true and PlayersHit[Hit.Parent] == nil then
 
            Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(65) --You can change to whatever damage you want

            PlayersHit[Hit.Parent] = true
            task.wait(1)
            PlayersHit[Hit.Parent] = nil
            Player.Leaderstats.Coins.Value += 10 -- Changed line you can customize

        end
    end
end)

Alright so, presuming you don’t have a leaderstats system aleady added you can you use this

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 0
	Cash.Parent = leaderstats
end) -- This is in SERVERSCRIPTSERVICE!!

Now that we have a cash system added we can award player for killing others!

Handle.Touched:Connect(function(Hit) --When player clicked 
  local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) -- this is just owner of tool
    if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= Tool.Parent then
        if Debounce == true and PlayersHit[Hit.Parent] == nil then
            Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(65) --You can change to whatever damage you want
            if Hit.Parent:FindFirstChild("Humanoid").Health <= 0 then
			if Player then
				Player.leaderstats.Cash.Value += 15 -- Player is awared 15 cash for killing them
			end
			end
            PlayersHit[Hit.Parent] = true
            wait(1)
            PlayersHit[Hit.Parent] = nil
        end
    end
end)
1 Like

Does this go into the sword script?

The second script yes. the first one is just to make a leaderstats for players joined (make sure its in servrescriptservice)

I’ve already added a leaderstats. I’ll try, I’m assuming he’ll have to do animations and stuff himself? I don’t see anything with animations in there. Or do I just add this onto and not replace it?

You just replace the damage part with the one i posted.

Okay. I will try right now then.

I will try this. Thank you for responding.