I need help with math.random

So I decided to make it so a new part will be inserted into the game if the player click his mouse, but giving every new part a random position is not as easy as I tought it is and I’d like to know why doesn’t this work. Thanks!

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

mouse.Button1Down:connect(function()
	local part = Instance.new("Part")
	part.Parent = game.Workspace
	part.Position = Vector3.new(math.random(1000,1000,1000),math.random(1000,1000,1000),math.random(1000,1000,1000))
	part.Anchored = true
	part.Color = Color3.new(1, 1, 1)
	part.Material = "SmoothPlastic"
end)
2 Likes

math.random at least expects 2 arguments, a minimum and a maximum value, you gave it 3 values and they’re all the same, you’re better off setting the XYZ to 1000 in that case, if y ou want random positioning, just change the first 1000 in all 3 of them to sometihng lower than 1000

2 Likes

I never saw people using math.random like this before

this isn’t how you use it, use it like:

print(math.random(1,10))

-- Output: 4 (or any number that's around 1 and 10)
2 Likes

Thank you all for the answers, but I just realised how dumb mistake that was, my brain told me to put 3 numbers in every single one of them since there is XYZ. I completely forgot the point of that math.random

1 Like