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

How to copy an object from ServerStorage to different locations depending on script?

I want multiple blocks to be clickable across my game, and if you click it i want it to paste a model from ServerStorage above those clickable blocks.

local storage = game:GetService("ServerStorage")
local part = storage["squareGreen2"]:clone() -- Change "Part" to the part name.
part.Parent = game.Workspace
part.Position = Vector3.new(2.25, 688.658, 665.099)

1 answer

If I am understanding what you are trying to say correctly, you need to run a for loop at the start of the game to get all of those clickable blocks to get their position once clicked.

It's very hard to explain, but the solution is simple:

local storage = game:GetService("ServerStorage")

for i,v in pairs(game.Workspace:GetChildren()) do
	if v.Name == "ClickableBlock" then
		v.ClickDetector.MouseClick:connect(function()
			local part = storage["squareGreen2"]:clone()
			part.Parent = game.Workspace
			part.Position = v.Position
		end
	end
end

I hope you understand what I meant, and I hope I understood your question correctly! Feel free to message me if you're still confused or that isn't what you meant. :)

1 comment

0

I apologise if the connect line for the ClickDetector function is incorrect, I don't use ClickDetectors often.

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