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

I want to make a part get a random pos??

		local Positions = game.Workspace.Positions:GetChildren()
		local Pos = Positions[math.random(1, #Positions)]
		local thing = game.Lighting.Noob:Clone()
		thing.Parent = game.Workspace
		thing.Position = Pos.Position

that is my script it won't work HELP PLEASE :(

2 comments

0

Is workspace.Positions a group of parts?

0

Yes its in a model

1 answer

Since you called the item you were cloning a "noob" so I assumed it was like a NPC or something. So first of all, LIGHTING is NOT meant to be for storage. There is ReplicatedStorage, or ServerStorage for all your client and server needs. Assuming the "noob" is a NPC, you cannot set the position simply by setting its position. You should use CFrame like so

local Positions = game.Workspace.Positions:GetChildren()
local Pos = Positions[math.random(1, #Positions)].Position --assuming you want to access the position of this object
local thing = game.Lighting.Noob:Clone()
thing.CFrame = Pos.Position
thing.Parent = workspace

Setting the parent BEFORE you set the properties (ex:size, position, etc) CAUSES A DELAY. Sure, the delay may seem short, but what if you wanted to spawn in a million wall parts? That would be about 10-20 seconds of lag (i never tested spawning a million wall parts) if you set the PARENT before the size, position, etc like mentioned in one of the tip of the days. If you would like to see more about this, see this. Now, using Instance.new(classname, parent) is deprecated, however, you can still use it, but it is NOT recommended. They deprecated it in the wiki. Hope this helps!

5 comments

0

if you said lighting is terrible for storage why did you use it on line 3 lol

0

cuz he didnt move it yet

0

This does not work for me :/

0

Ohh, right.

0

Edited it.

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