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

How to position random around a certain object?

Hi, I am trying to make spawn a part near another part, i was using it to be random so when it spawn it does really near the target. Can someone got a answer to that?

1 answer

✓ Accepted answer

if you want to make a part spawn near an another part you must :

Click on the part to know his position (I will say that it is at X = 0,Y = 0,Z = 0 to make it easier)

choose a radius for you new part to spawn (I will say 10 in each direction but it can be 1 000 000 ) So, you have your part and you want to spawn another one so you must begin your script with :

local RandomPart = Instance.new(“Part”) --The part is spawning  
RandomPart.Parent = workspace --[[ here, i parented the part to the workspace, that mean that i have set the part in the workspace]]--  
RandomPart.Name= “RandomPart” --[[The name of the part is now “RandomPart”]]--  
local X = math.random(-10,10) --[[I set a variable between -10 and 10 on the X vector]]--  
local Y = math.random(-10,10) --same for Y  
local Z = math.random(-10,10)-- and for Z too  
RandomPart.Position = Vector3.new(X,Y,Z) --[[I took the 3 variable and I put them in the RandomPart.Position with Vector3(it’s used for position in a 3D environement) you can find the RandomPart.Position by clicking on the part in the toolbox and searching for Position in the properties of the part]]--

7 comments

0

I got trouble with editing but i finally finished xD

0

No, that doesn't work.

0

Also, you have WAY too many comments (or your comments are just WAY too long).

0

It's working for me so i'm quite surprised it isn't working for you but for the comments that's true ^^ ill try to make the comments more compact next time !

0

Thank you Louix, it's really helpful, i actually thought of that but never knew how to or if this was even possible ! :D

0

Thank you Louix, it's really helpful, i actually thought of that but never knew how to or if this was even possible ! :D

0

No problem Shematics good luck for your game!

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