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

Why isn't the value multiplying correctly?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Ad

Answer this question