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

I'm struggling with math.random. Why is it printing the same thing?

It's supposed to generate a new number every time the function is called with the variable SpawnChance. Instead, it generates values such as '1C94F9E0' and whatnot, and it prints the same thing over and over.

I want it to print a randomized number from 1 to 200, and a different number every time the function is called.

math.randomseed(tick())

function SpawnChests()
local SpawnChance = math.random (1,200)
print(SpawnChests)
end


while true do
wait(5)
SpawnChests()
end

1 answer

✓ Accepted answer

The problem is that you are printing the function not the variable, so the tostring() function will be called on the function.

math.randomseed(tick())

function SpawnChests()
	local SpawnChance = math.random (1,200)
	print(SpawnChance ) -- you need to print the variable not the function
end


while true do
	wait(5)
	SpawnChests()
end

1 comment

0

This is what I get for scripting at midnight, haha. Thank you!!

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