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

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

Asked by 8 years ago

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

Log in to vote
1
Answered by 8 years ago

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. :)

0
I apologise if the connect line for the ClickDetector function is incorrect, I don't use ClickDetectors often. WeMakeTheGame 20 — 8y
Ad

Answer this question