Still have questions? Join our Discord server and get real time help.
0

# How Do I Generate a Random Position for A Model?

So I want to make this system that clones a cage and spawns it somewhere. Here is my code so far:

local spawner = game.ReplicatedStorage.SpawnCage1
local cage = game.ServerStorage.Cage:Clone()

spawner.Changed:Connect(function()
if spawner.Value == true then
cage.Parent = workspace
local position1 = Vector3.new(0,0,0)
local position2 = Vector3.new(10,0,0)
local position3 = Vector3.new(20,0,0)
local position4 = Vector3.new(30,0,0)
local chosenPos = {position1,position2,position3,position4}
cage.PrimaryPart.Position = math.random(1,#chosenPos)
elseif spawner.Value == false then
cage.Parent = game.ServerStorage
end
end)


Here is the error in the output: 17:30:12.412 - ServerScriptService.Cage1Spawner:12: bad argument #3 to 'Position' (Vector3 expected, got number)

I would really appreciate if someone helped me out with this. Thanks in advance!

1

cage.PrimaryPart.Position = math.random(1,#chosenPos)

cage.PrimaryPart.Position = chosenPos[math.random(1,#chosenPos)]