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

How to make if strenght ( in leaderboard ) = 100 then + 100 cash, and strenght reset to 0 ?

Asked by
PPJASK 19
3 years ago

How to make if strenght ( in leaderboard ) = 100 then + 100 cash, and strenght reset to 0 ? - How to make that ? - PPJASk -best regards

1 answer

Log in to vote
0
Answered by 3 years ago

Firstly we're of course making our leaderstats which I'm guessing you did already, just incase.

local Players = game:GetService("Players")
local Create = Instance.new

Players.PlayerAdded:Connect(function(player)
    local Folder = Instance.new("Folder") --Creating a folder called leaderstats to store data.
    Folder.Parent = player 
    Folder.Name = "leaderstats"

    local Strenght = Create("IntValue") --Creating a value thats gonna be used as strenght
    Strenght.Parent = Folder
    Strenght.Name = "Strenght"
    Strenght.Value = 0

    local Cash = Create("IntValue")--Here too, Cash instead.
    Cash.Parent = Folder
    Cash.Name = "Cash"
    Cash.Value = 0
end)

Then of course, the checking and subtracting.

We'll create a function with 3 arguments, being the leaderstats folder, the strenght value, and the cash value.

Afterwards we'll check if the strenght value is higher or equal to 100. Then we're adding 100 cash onto the current cash value. Setting the strenght value back to 0.

local Subtract = function(leaderstats,strenght,cash)
    if strenght.Value <= 100 then
        cash.Value+=100
        strenght.Value = 0
    end
end

Of course, If you do not know how to connect these functions here's an example using a Remote Event.

Event.OnServerEvent:Connect(function(player)

      local leaderstats = player:WaitForChild("leaderstats")
      local strenght = leaderstats:WaitForChild("Strenght")
      local cash = leaderstats:WaitForChild("Cash")

      Subtract(leaderstats,strenght,cash)

end)

Defining each of our values and the folder that's created when the player joins the game. Then calling our functions with the defined values.

Hope it helps.

Ad

Answer this question