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

ServerStorage only adding one part in a loop?

Asked by 3 years ago

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

0
Please use the formatting options provided on this website to make it easier for us to read your code. appxritixn 2235 — 3y

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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
Ad

Answer this question