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

How would I award 'money' to a player for killing another player?

I have made this 'saving money system' but I also want it to award the player 5 points for every kill and assign 1 'death' for every death. How would I go about doing this?

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder",player)
    leader.Name = "leaderstats"
    local Cash = Instance.new("IntValue",leader)
    Cash.Name = "Money"
    Cash.Value = ds:GetAsync(player.UserId) or 0
    ds:SetAsync(player.UserId, Cash.Value)
    Cash.Changed:connect(function()
        ds:SetAsync(player.UserId, Cash.Value)
    end)
end)

2 comments

0

As I see from your comment to the answer below, you do not want leaderstats script of Roblox. This was one of the best options. Another option is scripting weapons for your goal. It should be like: Humanoid:TakeDamage(20) if Humanoid.Health == 0 then Cash.Value = Cash.Value + 5

0

I have a leaderboard that adds 5 points for each kill and 1 death for each death, but when I added the script above, both of them don't load into the actual game. I have watched many videos but couldn't find any that would fix this issue.

1 answer

The script you currently have saves the cash to the datastore (and, btw, you should remove line 9 -- you only want to save their cash perhaps periodically and definitely when they leave (using the PlayerRemoving event), not immediately after you've loaded it).

Look into Roblox's leaderboard script (in the Toolbox). It increases variables on kill/death; you can use the same ideas to increase money/points/whatever you like.

2 comments

0

I have already tried messing around with the 'LinkedLeaderboard' script in ROBLOX but it doesn't seem to work for me.

0

Ideally you should study what events it uses, emptying out code that you don't want to run and replacing it with your own. It handles death count (and kill count, though the weapons involved have to cooperate with it by tagging the humanoid they're attacking, iirc).

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