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

Why isn't the value multiplying correctly?

I am having trouble with this code

game.ServerStorage.ClickDetector:Clone().Parent = RainBB

RainBB.ClickDetector.MouseClick:Connect(function(player)

local PlayerRain = player.leaderstats.Rain
local PlayerRebirth = player.leaderstats.Rebirths
local PlayerMulti = player.leaderstats.Multiplier
	
	
PlayerRain.Value = PlayerRain.Value + 1 * (PlayerRebirth.Value) + 1 * (PlayerMulti.Value)

	

RainBB:Destroy()
wait()
end)

end

Basically, when you click the rain block, it will give you rain in your leaderstats. But for some reason, It is not multiplying with the rebirths and multiplier. I really need help with this in order to release my game. Thanks!

1 answer

✓ Accepted answer

You need to use proper parentheses.

PlayerRain.Value = PlayerRain.Value + 1 * (PlayerRebirth.Value) + 1 * (PlayerMulti.Value)
--should be 
PlayerRain.Value = (PlayerRain.Value + 1) * ((PlayerRebirth.Value) + 1) * (PlayerMulti.Value)
--You gotta remember pemdas
--Parentheses
--Exponents
--Muiltiplication
--Division
--Addition
--Subtraction

You were trying to add +1 to rebirths and rain, but really what happened was you multiplied rebirths and rain by 1.

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