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

Why does this script only clone a part once?

Asked by 8 years ago

My script is supposed to put different blocks in different places. As of now, if x, y, or z equal the same thing (for example, if x and y both are 1), then it will only clone the first one that shows up. Why is this?

part = script.Parent
dirt = game.ReplicatedStorage:FindFirstChild("dirt"):Clone()
stone = game.ReplicatedStorage:FindFirstChild("stone"):Clone()
sand = game.ReplicatedStorage:FindFirstChild("sand"):Clone()

function onClick()
    local x = math.random(3)
    if x == 1 then
        dirt.Parent = workspace
        dirt.Position = part.Position + Vector3.new(4,0,0)
    end

    if x == 2 then
        stone.Parent = workspace
        stone.Position = part.Position + Vector3.new(4,0,0)
    end

    if x == 3 then
        sand.Parent = workspace
        sand.Position = part.Position + Vector3.new(4,0,0)
    end

    local y  = math.random(3)
    if y == 1 then
        dirt.Parent = workspace
        dirt.Position = part.Position + Vector3.new(0,4,0)
    end

    if y == 2 then
        stone.Parent = workspace
        stone.Position = part.Position + Vector3.new(0,4,0)
    end

    if y == 3 then
        sand.Parent = workspace
        sand.Position = part.Position + Vector3.new(0,4,0)
    end

    local z  = math.random(3)
    if z == 1 then
        dirt.Parent = workspace
        dirt.Position = part.Position + Vector3.new(0,0,4)
    end

    if z == 2 then
        stone.Parent = workspace
        stone.Position = part.Position + Vector3.new(0,0,4)
    end

    if z == 3 then
        sand.Parent = workspace
        sand.Position = part.Position + Vector3.new(0,0,4)
    end

    print(x)
    print(y)
    print(z)
    part:Destroy()
end

part.ClickDetector.MouseClick:connect(onClick)

1 answer

Log in to vote
0
Answered by 8 years ago

you do realised, you should have use

x = math.random(1,3)

if x == 1 then
-- Do something
elseif x == 2 then
-- Do something else
elseif x == 3 then
-- Do this thing
end

Welp, hope this help!

0
This is not at all helpful. DrCylonide 158 — 8y
0
Oh wait i found the problem (i think!), I think instead of Cloning it in the first place. Make it clone when onclick, so basically clone the sand/stone/dirt then put it in workspace after clicked FlaminSparrow 65 — 8y
0
^ I tried that, it put the part where it was before it was placed into ReplicatedStorage DrCylonide 158 — 8y
Ad

Answer this question