Adding value not working

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)

Anyone know what’s up?

1 Like

I think you were supposed to call the heat’s value.

math.random only takes integers

1 Like

Heat does not have a Value. It errors in my output.

That sucks. If I were to use decimals, should I divide the result from math.Random by, let’s say, 10?

I’m pretty sure math.random() is obselete. ROBLOX now encourages the use of Random.new(), which is “more random” than math.random().

More info: Random | Documentation - Roblox Creator Hub
Oh, and also: A Random Feature

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.

For example :

print(math.random(0,100)/10)

You could probably do this if you wanted 0.1, I haven’t been using math.random much.

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.

1 Like

Oh, I see! Yeah, 0 and 1 is too close to each other.

1 Like

Actually, math.random and Random use the same algorithm now.

2 Likes

I still prefer using Random.new() since it’s newer, and probably more reliable.

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.

(lol i just realized i used 6 instead of 5)

1 Like