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

Script:9: attempt to perform arithmetic on a userdata value?

why does it say "Script:9: attempt to perform arithmetic on a userdata value" when i want to make a randomized orientation?

cg.Orientation=Vector3.new((cg.Orientation.X+Random.new(-10,10)),(cg.Orientation.Y+Random.new(-10,10)),(cg.Orientation.Z+Random.new(-10,10)))

1 answer

✓ Accepted answer

You probably want to use math.random() instead.

cg.Orientation = Vector3.new(
					cg.Orientation.X + math.random(-10,10),
					cg.Orientation.Y + math.random(-10,10),
					cg.Orientation.Z + math.random(-10,10)
				)

Random is more for when you have the same random numbers each time. This will print the same 30 numbers each time because we have the seed 1337

Your code doesn't work because you are creating a object of the type Random , not getting the random number from the object. random:NextInteger (1,10) gets the random number.

local seed = 1337
local random = Random.new(seed)

for i = 1, 30 do
	print(random:NextInteger (1,10))
end

Technically we could use random seed, but we want new random numbers each time, so that's a lot more code to write.

2 comments

0

yo i honestly feel so stupid for using the new random thing instead of just "math.random"

0

you can use random.new() but its more work and that's not what it's made for

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