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

Making an object generator?

Asked by 7 years ago

I have a minigame server where I was hoping to make a conveyor belt challenge. In the challenge, you run on a conveyor belt with lava blocks with randomly generated sizes being dropped at the beginning of the conveyor belt causing you to have to jump around them to stay on. I have created a conveyor belt, but I have no idea how to make an object that generates a constant flow of lava blocks. Please help!

0
I'm not sure what your asking but have a look at this wiki article: http://wiki.roblox.com/index.php?title=Creating_Parts_via_Code shadownetwork 233 — 7y
0
My question isn't really about how to build an object, rather a question about how to script an object to do a task. keatenn0987 5 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

Concept

You can think of this the same way you'd think of scripting a tycoon dropper. A constant loop, cloning an object and placing it. Only differences are:

  • 1) You can't let the conveyor do the work, it will look messy. Parts must be anchored, positioned, and CFramed in a loop.

  • 2) You need to randomize the size, as well as the position.

Steps

So, step one.. have a while loop constantly clone a part.

Step 2 .. Randomize the size of the part.

Step 3.. Position the part on the conveyor.

Step 4.. CFrame the part in a loop

Step 5.. Destroy the part when you don't need it anymore.

Code

local part = game.ServerStorage.KillBrick --This is the part template
local conveyor = workspace.Conveyor --This is the conveyor
local spawnPos = conveyor.Spawn --This is the kill bricks' spawn position
local interval = 2; --This is the spawn rate of the kill bricks
local lifetime = 20; --This is how long the kill bricks will exist

--Reference the conveyor's size to determine the kill brick's possible size
local size = conveyor.Size.X

while wait(interval) do  --Step 1
    local c = part:Clone();
    c.Anchored = true;
    --Step 2
    c.Size = Vector3.new(math.random(size),c.Size.Y,math.random(1,5));
    --Step 3
    local dif = size/2 - c.Size.X/2; --Account for side margins
    c.CFrame = spawnPos.CFrame
             * CFrame.new(math.random(-dif,dif) or 0,0,0);
    c.Parent = workspace;
    spawn(function()
        local _then = tick();
        while wait() do
            c.CFrame = c.CFrame * CFrame.new(0,0,-.5); --Step 4
            local now = tick();
            if (now - _then) > lifetime then
                c:Destroy(); --Step 5
            end
        end
    end)
end

You may see an example of this exact code in action here.

Ad

Answer this question