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

Why does this script only clone a part once?

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

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!

3 comments

0

This is not at all helpful.

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

0

^ I tried that, it put the part where it was before it was placed into ReplicatedStorage

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