Roblox LUA does not understand what you want to do.
It's going to generate the same random number every time.
I'd also recommend putting the spawn in ReplicatedStorage so we can clone it.
And also create a folder in workspace called spawns where we parent the spawns later on
So put it in a while loop like this;
local MainSpawn = game.Workspace.MainSpawn:Clone()
local AllSpawns = game.Workspace.Folder
function generate()
local PosX = math.random(-12.96 , 217.21)
local PosZ = math.random(71.05 , -46.1)
local NewVector = Vector3.new(PosX, 41, PosZ)
return NewVector
end
while true do
wait()
local PartVector = generate()
MainSpawn.Position = PartVector
MainSpawn.Parent = game.Workspace.Folder
if #AllSpawns:GetChildren() > 10 then
break
end
end
The things you need to learn;
Returning; basically stops the function like a break in loops. And you can define the variable too.
# is a number for something that isn't a numbervalue:
Here's an example
function checkplayers()
if #game.Players:GetPlayers() < 2 then
print("2 or more player required to play the game")
end
end
while wait(2) do
checkplayers()
end
3 comments
When specifying the range in which you want the randomly selected number to be, I would put the lower number first. On line 5, you put the lower number second. Switch them and see if it works.
Just read the wiki , its a simple thing. its one of the easiest thing talking about math in lua.
Show us the code where you are spawning yourself