Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to position random around a certain object?

Asked by
Shematics 117
5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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]]--
0
I got trouble with editing but i finally finished xD Louix27626 83 — 5y
0
No, that doesn't work. DeceptiveCaster 3761 — 5y
0
Also, you have WAY too many comments (or your comments are just WAY too long). DeceptiveCaster 3761 — 5y
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 ! Louix27626 83 — 5y
View all comments (3 more)
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 Shematics 117 — 5y
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 Shematics 117 — 5y
0
No problem Shematics good luck for your game! Louix27626 83 — 5y
Ad

Answer this question