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

How do i make this Boulder spawner work?

Asked by
TickoGrey 116
4 years ago
while true do
    local cloned = game.ServerStorage.Boulder:Clone()
    local spawn = math.random(1,3)
    if spawn == 1 then
        cloned.CFrame = CFrame.new(-1467.45, 459.622, 37.152)
    end
    if spawn == 2 then
        cloned.CFrame = CFrame.new(-1467.45, 459.622, 21.152)
    end
    if spawn == 3 then
        cloned.CFrame = CFrame.new(-1467.45, 459.622, 12.152)
    end
    wait(2)
end

im trying to spawn a boulder randomly but idk why it is not working

1
You're not setting the parent of the cloned boulder. cloned.Parent = workspace. killerbrenden 1537 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

When cloning an instance, it's not parented on its own, you'd have to write a separate line for it.

while wait(2) do --Every 2 seconds, the loop executes
    local cloned = game.ServerStorage.Boulder:Clone()
    cloned.Parent = game.Workspace
    local spawn = math.random(3) --Generates a number between 1 and 3, math.random(1, 3) only chooses between 1 and 3
    if spawn == 1 then
        cloned.CFrame = CFrame.new(-1467.45, 459.622, 37.152)
        elseif spawn == 2 then
        cloned.CFrame = CFrame.new(-1467.45, 459.622, 21.152)
        elseif spawn == 3 then
        cloned.CFrame = CFrame.new(-1467.45, 459.622, 12.152)
    end
end
Ad

Answer this question