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

ServerStorage only adding one part in a loop?

So I made this script and it only adds one but I want it to add multiple here's the script.

local Storage = game.ServerStorage local RandomNumber = math.random(10, 100)

local Gem = Storage.Gem:Clone() while true do wait(RandomNumber)

Gem.Parent = game.Workspace Gem.CFrame = game.Workspace.GemSpawner.CFrame print("Added") end

1 comment

0

Please use the formatting options provided on this website to make it easier for us to read your code.

1 answer

The way you have it, you are dealing with 1 instance, the cloned gem, instead of repeatedly cloning the gem.

All you have to do is clone the gem while inside the while loop rather than outside:

local Storage = game.ServerStorage 
local RandomNumber = math.random(10, 100)

-- local Gem = Storage.Gem:Clone()
-- ^^Used to be here
local OriginalGem = Storage.Gem

while true do 
	wait(RandomNumber)
	local Gem = OriginalGem:Clone() -- Now the gem is cloned here
	Gem.Parent = game.Workspace 
	Gem.CFrame = game.Workspace.GemSpawner.CFrame 
	print("Added") 
end

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