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

How to situate a part on a random point on another part?

Heres my code.

local yoffset = 1    
local minx = (v.Baseplate.Size.X / 2) - v.Baseplate.Position.X
local maxx = (v.Baseplate.Size.X / 2) + v.Baseplate.Position.X
local minz = (v.Baseplate.Size.Z / 2) - v.Baseplate.Position.Z
local maxz = (v.Baseplate.Size.Z / 2) + v.Baseplate.Position.Z
local y = (v.Baseplate.Size.Y / 2) + v.Baseplate.Position.Y + yoffset
                
local randX = mainrand.RandomMINMAX(minx,maxx)
local randZ = mainrand.RandomMINMAX(minz,maxz)
                
local clone = q.Asset:Clone()
                
print("located at minimum "..minx.." maximum "..maxx..",".." "..minz.." "..maxz)
clone.Position = Vector3.new(randX,y,randZ)
clone.Parent = v.Extras

https://gyazo.com/380924e4ebc236fbf150faa95116248a The rocks are supposed to be on the sand.

1 answer

You could do something like this:

math.randomseed(tick())

local target = workspace.Baseplate
local x = math.random(target.position.X - target.Size.X / 2, target.position.X + target.Size.X / 2)
local z = math.random(target.position.Z - target.Size.Z / 2, target.position.Z + target.Size.Z / 2)

1 comment

0

Why did I never get this until 5 days later?

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