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

positioning a part in a random position between two points?

I want to spawn a part inside a box/part with two attachments as the limit. this is what I have so far.

local r = Random.new()

local part = Instance.new("Part")
part.Parent = game.Workspace
part.Anchored = true
local a = script.Parent.Attachment1
local b = script.Parent.Attachment2

while true do
wait(1)	
local x = r:NextInteger(1,a.WorldPosition.X - b.WorldPosition.X)
local y = r:NextInteger(1,a.WorldPosition.Y - b.WorldPosition.Y)
local z = r:NextInteger(1,a.WorldPosition.Z - b.WorldPosition.Z)

part.Position = Vector3.new(x,y,z)
end

it does partially work but instead of spawning in between the two points it does it in another location.

2 answers

NextInteger must be used in place of .new like so:

Random:NextInteger(x, y)

The way you have it is

Random.new:NextInteger(x, y)

Also since random takes

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