Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does converting Coins into Rebirths not work?

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

1 comment

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.

1 answer

✓ Accepted answer

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)

3 comments

1

this man is big smart man

0

this works fine however it takes away all of my rebirths

0

Edited my asnwer so it does not take away current rebirths owned by the user.

This discussion is preserved as it was. New answers, comments, and votes are closed.