Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make it so if a player kills somebody then the player gets 50 cash?

Asked by 3 years ago

The Leaderstats are called Cash

2 answers

Log in to vote
0
Answered by
HDMini 30
3 years ago

The easiest way to do this is to use leader stats and tagging.

First, you'll need to set up the leaderboard. To do this, you'll need to insert a folder named "leaderstats" with an IntValue called "Cash" into every player.

Server Script:

01local Players = game:GetService("Players")
02 
03local function leaderboardSetup(player)
04    local leaderstats = Instance.new("Folder")
05    leaderstats.Name = "leaderstats"
06 
07    -- Stats are individual values such as an IntValue
08    local cash = Instance.new("IntValue")
09    cash.Name = "Cash"
10 
11    cash.Parent = leaderstats
12    leaderstats.Parent = player
13end
14 
15-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event
16Players.PlayerAdded:Connect(leaderboardSetup)

Next, you'll want to listen for when a player dies. One way to do this is to use the "Died" event in the humanoid. Once the "Died" event is fired, give the tagger 50 cash.

Server Script:

01local Players = game:GetService("Players")
02 
03Players.PlayerAdded:Connect(function(player)
04    player.CharacterAdded:Connect(function(character)
05        local humanoid = character.Humanoid
06 
07        humanoid.Died:Connect(function()
08            local tag = humanoid:FindFirstChild("creator")
09 
10            if tag and tag.Value then
11                tag.Value.leaderstats.Cash.Value += 50
12            end
13        end)
14    end)
15end)

Now you'll need to put a tag inside of a player when they get hit. ROBLOX endorsed weapons such as the classic sword do this automatically, but you can use these functions inside of your own weapon's hit logic.

At it's most basic level, a sword script should look like this.

Weapon Script (Server Script):

01local Players = game:GetService("Players")
02local Debris = game:GetService("Debris")
03 
04local tool = script.Parent
05local handle = tool:WaitForChild("Handle")
06 
07local Damage_Per_Hit = 10
08 
09-- I just stole the TagHumanoid() and UntagHumanoid() functions from the classic sword
10 
11-- Inserts a new "ObjectValue" inside of the humanoid with the tagger's player object
12local function TagHumanoid(humanoid, player)
13    local creatorTag = Instance.new("ObjectValue")
14    creatorTag.Name = "creator"
15    creatorTag.Value = player
View all 48 lines...
Ad
Log in to vote
0
Answered by 3 years ago
1player.CharacterAdded:Connect(function(Character)
2        Character.Humanoid.Died:Connect(function(Died)
3            local creator = Character.Humanoid:FindFirstChild("creator")
4            local leaderstats = creator.Value:FindFirstChild("leaderstats")
5            if creator ~= nil and creator.Value ~= nil then
6                leaderstats.Coins.Value = leaderstats.Coins.Value + 10 -- change to whatever amount of coins you want to award also change "coins" to "cash"
7            end
8        end)

This is what I use as a KillForCash script hope this helps.

Answer this question