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

How Do I sell something from the in-game leader-board and make it into a different currency?

Asked by 5 years ago
Edited 5 years ago

So what I'm making is a game where you sell your deaths for coins but it has been stumping me for awhile I have been questing how to even make the deaths into coins by touching a block so that's why I don't have a script because I don't know how to start it or make it basically what mining sim does but with no backpack but from the leader-board.

2 answers

Log in to vote
0
Answered by
Kymaraaa 116
5 years ago

First of all you'll need to track Player Deaths.

Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    local Deaths = Instance.new("IntValue")
    Deaths.Name = "Deaths"
    Deaths.Parent = Leaderstats
    local Money = Instance.new("IntValue")
    Money.Name = "Money"
    Money.Parent = Leaderstats
    Leaderstats.Parent = Player

    Player.CharacterAdded:Connect(function(Character)
        Character:WaitForChild("Humanoid").Died:Connect(function()
            Deaths.Value = Deaths.Value + 1
        end)
    end)
end)

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!

local Multiplier = 1
Part.Touched:Connect(function(Hit)
    local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
    if Player then
        local Leaderstats = Player.leaderstats
        Leaderstats.Money.Value = Leaderstats.Money.Value + (Leaderstats.Deaths.Value * Multiplier)
        Leaderstats.Deaths.Value = 0
    end
end)

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.

0
Thx vincentthecat1 199 — 5y
0
so what you mean for the last script is that I get a block then I step on it and it converts my deaths in to coins? vincentthecat1 199 — 5y
0
Yes. Don't forget to mark it as the right answer if I helped. Kymaraaa 116 — 5y
0
oh and I have a Leaderboard do I need to use the leaderboard you made or the leaderboard I have? vincentthecat1 199 — 5y
View all comments (3 more)
0
It wont work. vincentthecat1 199 — 5y
0
Well you obviously have to change the code to work with your custom leaderboard. Kymaraaa 116 — 5y
0
I allready found something bye vincentthecat1 199 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

so what you mean for the last script is that I get a block then I step on it and it converts my deaths in to coins?

Answer this question