New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 5 months ago
Edited 5 months 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:

local GrassIsCutted = false -- ignore this. its for a different purpose

local OriginalPiece = game.ServerStorage.OriginalPart

local 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)}

function duplicatePiece()

math.randomseed(tick())
local position = positionsTable[math.random(1,#positionsTable)]

local clonedPiece = OriginalPiece:Clone()

clonedPiece.Position = position
clonedPiece.Parent = game.Workspace

end


while true do

wait(10)
duplicatePiece()
end

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 — 5mo
0
I tried doing it, still does not work however. Thanks for . trying tho. VVickedDev 39 — 5mo

1 answer

Log in to vote
0
Answered by 5 months 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

clonedPiece.Parent = workspace

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

Ad

Answer this question