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

Spawning a part in random positions gone wrong? (Updated)

Asked by 6 years ago
Edited 6 years ago

Basically, I am trying to spawn this part around a specific region on a map. I tried using Vector values to spawn the part but it still does not work. Instead of spawning in between that region, the piece only spawns on the positions. Help Is Appreciated and UpVoted! This is my following code:

01local GrassIsCutted = false -- ignore this. its for a different purpose
02 
03local OriginalPiece = game.ServerStorage.OriginalPart
04 
05local positionsTable = {Vector3.new(-59.5, 1.5, -23.5), Vector3.new(-59.5, 1.5, 26.5),Vector3.new(-8.23, 1.5, 26.467),Vector3.new(-8.5, 1.5, -23.5)}
06 
07function duplicatePiece()
08 
09math.randomseed(tick())
10local position = positionsTable[math.random(1,#positionsTable)]
11 
12local clonedPiece = OriginalPiece:Clone()
13 
14clonedPiece.Position = position
15clonedPiece.Parent = game.Workspace
16 
17end
18 
19 
20while true do
21 
22wait(10)
23duplicatePiece()
24end

I placed the OriginalPiece in the ServerStorage by the way. Thank you for taking your time to read and debug this. :)

0
Yeah so the script makes a copy of the piece and DOES position it; however, you do need to set its parent to something (For example: clonedPiece.Parent=game.Workspace) curtisornot 0 — 6y
0
I tried doing it, still does not work however. Thanks for . trying tho. VVickedDev 54 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You forgot to set its parent to workspace; you won’t see it in your game if you don’t do this. So simply do

1clonedPiece.Parent = workspace

right after you clone it and you should see it in your game.

Ad

Answer this question