I’m writing a script that when you click a block, it will add a random value to a Fire’s Heat and then repeat. Whenever I click the block, the NumberValue (named HeatVal) always returns as 0. Here is my code:
local rep = game:WaitForChild("ReplicatedStorage")
script.Parent.ClickDetector.MouseClick:Connect(function()
local p = math.random(0, 0.1)
local heat = script.Parent.FirePart.Fire.Heat
local heatval = rep.HeatVal.Value
p = heatval
heat = heat + heatval
print(heat)
end)
Yes, for random double numbers, a work around is to use math.random for 2 integers over a desired range, for example 0 and 100 and then divide the value returned by 10.
But this would have the possibility of printing 0 or 0.1 only since there is no integer between 0 and 1, other than the neutral integer 0 and integer 1 on the bounds, so this wouldn’t give any other random decimal number.
Yeah it has its advantages. Like the seed only being local to the Random instance. As well as the Random::NextNumber method which fits OP’s use case and does accept decimals.