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

Why does converting Coins into Rebirths not work?

Asked by 3 years ago
script.Parent.Touched:Connect(function(Object)
    local Player = game.Players[Object.Parent.Name]
    if  Player.leaderstats.Coins.Value >= 100 then
        Player.leaderstats.Rebirths.Value =  Player.leaderstats.Rebirths.Value + (Player.leaderstats.Coins.Value/100)
        Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - (Player.leaderstats.Coins.Value/100) * 100

    end

end)

My coin value ends up being 0

0
Okay, so pretend you have 100 coins. On line 5, it will be like doing: Player.leaderstats.Coins.Value = 100 - (100/100) * 100. 100 - (100/100) * 100 = 0, which makes your coins 0. raid6n 2196 — 3y

1 answer

Log in to vote
2
Answered by
uhi_o 417 Moderation Voter
3 years ago
Edited 3 years ago

You can use the / operator to check how many times 100 goes into the amount of coins the user has.

script.Parent.Touched:Connect(function(Object)
    local Player = game.Players[Object.Parent.Name]
    if  Player.leaderstats.Coins.Value >= 100 then
        local RebirthsToAward = math.floor(coins/100) -- Preventing decimals
        Player.leaderstats.Rebirths.Value += RebirthsToAward
        Player.leaderstats.Coins.Value -= RebirthsToAward * 100 -- Subtracting the amount of coins necessary

    end
end)

1
this man is big smart man raid6n 2196 — 3y
0
this works fine however it takes away all of my rebirths catsalt29 57 — 3y
0
Edited my asnwer so it does not take away current rebirths owned by the user. uhi_o 417 — 3y
Ad

Answer this question