I make core game and confronted with problem that my script doesn’t work.
When heatlevel value == 1,2,3 or 4 temp value needs to rise but it’s value 0, nothing in output. robloxapp-20230316-1916068.wmv (122.6 KB)
Video with that problem ^
Help please!
local items = script.Parent
if items.HeatLevel.Value == 1 then
items.Temp.Value += math.random(2,15)
elseif items.HeatLevel.Value == 2 then
items.Temp.Value += math.random(7,30)
elseif items.HeatLevel.Value == 3 then
items.Temp.Value += math.random(12,54)
elseif items.HeatLevel.Value == 4 then
items.Temp.Value += math.random(15,69)
end
I think the script isnt in a loop, it all runs straight away, even when you get to the clicking button.
while task.wait(1) do
if items.HeatLevel.Value == 1 then
items.Temp.Value += math.random(2,15)
elseif items.HeatLevel.Value == 2 then
items.Temp.Value += math.random(7,30)
elseif items.HeatLevel.Value == 3 then
items.Temp.Value += math.random(12,54)
elseif items.HeatLevel.Value == 4 then
items.Temp.Value += math.random(15,69)
end
end
You can do this with your code, @weakroblox35’s code might be better but this is just another method:
local usableValues = {1, 2, 3, 4} -- values you can use
local values = {{2, 15},{7, 30},{12, 54},{15, 69}} -- stored values to access
function add(num)
if usableValues[num] then -- if the value can be used
items.Temp.Value += math.random(values[num][1], values[num][2]) -- adds random by using stored values
end
end
-- whatever here:
add(items.HeatLevel.Value)
However if you want more far results, use Random.new()
local random = Random.new() -- Random (Instance? It could just be a table)
function add(num)
if usableValues[num] then -- if the value can be used
items.Temp.Value += random:NextInteger(values[num][1], values[num][2]) -- adds random by using stored values
end
end