P = Instance.new("Part")
P.Parent = workspace
while wait(1) do
Baseplate = game.Workspace:WaitForChild('Baseplate')
Location = math.random(0,Baseplate.Size.X,0,Baseplate.Size,0,Baseplate.Size.Z)
P.Position = Vector3.new(Location,0,Location)
end
✓ ANSWER ACCEPTED
How do I make it so that it spawns in a random position that is inside the parts size?
1 answer
✓ Accepted answer
If you are using the normal baseplate, you can use math.random for the X and Z component of based on half of the Baseplate's size since 0,0,0 is the center of the baseplate. It is also better to use local variables rather than non-local variables in this case.
local Baseplate = workspace:WaitForChild("Baseplate")
while true do
wait(1)
--Since (0,0,0) is the center of the baseplate we want to spread the part randomly between the half of the negative or positive of the baseplate size.
local X = math.random(-Baseplate.Size.X/2, Baseplate.Size.X/2)
local Z = math.random(-Baseplate.Size.Z/2, Baseplate.Size.Z/2)
local P = Instance.new("Part")
P.Position = Vector3.new(X, 0, Z)
P.Parent = workspace
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
