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

Why are the parts not spawning?

Asked by 9 years ago

I do not understand why the parts in ReplicatedStorage are not spawning on the Baseplate.. What is wrong with the script?

local storage = game:GetService('ReplicatedStorage')
local color = storage.Color:GetChildren()
local base = workspace.BasePlate

while wait(2) do
 math.randomseed(tick())
 local choose = color[math.random(1, #color)]:clone() 

 choose.Position = base.Position
end

2 answers

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
9 years ago

I encourage you, Darknesschaos, to read the relevant articles and documentation on the Official Roblox Wiki, for example, the page on the clone() method. On that page, you will see under the notes section that:

"The copy's Parent is initially nil."

This means that when you clone something, it initially doesn't belong anywhere, and so it won't, for example, appear in the workspace.

local storage = game:GetService('ReplicatedStorage')
local color = storage.Color:GetChildren()
local base = workspace.BasePlate

math.randomseed(tick()) --You only need to seed once, so keep this out of the loop
while wait(2) do

    local choose = color[math.random(1, #color)]:clone() 

    choose.Parent = workspace --Set the parent property of "choose" to "workspace"

    choose.Position = base.Position
end
Ad
Log in to vote
0
Answered by 9 years ago
local storage = game:GetService('ReplicatedStorage')
local color = storage.Color:GetChildren()
local base = workspace.BasePlate
local Parent_To_Base = false -- Set to true if you want it to parent IN the base.

while wait(2) do
 local choose = color[math.random(1, #color)]:clone() 
if Parent_To_Base then
choose.Parent=base
else
choose.Parent=game.Workspace
end
 choose.Position = base.Position
end

Answer this question