First of all you’ll need to track Player Deaths.
01 | Players.PlayerAdded:Connect( function (Player) |
02 | local Leaderstats = Instance.new( "Folder" ) |
03 | Leaderstats.Name = "leaderstats" |
04 | local Deaths = Instance.new( "IntValue" ) |
05 | Deaths.Name = "Deaths" |
06 | Deaths.Parent = Leaderstats |
07 | local Money = Instance.new( "IntValue" ) |
09 | Money.Parent = Leaderstats |
10 | Leaderstats.Parent = Player |
12 | Player.CharacterAdded:Connect( function (Character) |
13 | Character:WaitForChild( "Humanoid" ).Died:Connect( function () |
14 | Deaths.Value = Deaths.Value + 1 |
The code above creates the Leaderstats folder, Deaths value and Money value in the player which will be displayed on the PlayerList. When the Player dies, their Deaths Value is increased by 1.
Next, we’ll need to attach some code to a Part so that when it’s touched it’ll convert the your Deaths into Money!
2 | Part.Touched:Connect( function (Hit) |
3 | local Player = game:GetService( "Players" ):GetPlayerFromCharacter(Hit.Parent) |
5 | local Leaderstats = Player.leaderstats |
6 | Leaderstats.Money.Value = Leaderstats.Money.Value + (Leaderstats.Deaths.Value * Multiplier) |
7 | Leaderstats.Deaths.Value = 0 |
This code will convert your Deaths into Money. Right now you’ll get the same amount of Money as your Deaths. You can increase the amount you get by per death by increasing the Multiplier.
Anything less than 1 will give you less Money, anything more than 1 will give you more Money.