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

HOW DO YOU CLONE A MODEL FROM SERVERSTORAGE TO WORKSPACE?

Asked by
proo34 41
6 years ago

I've been trying to clone a model from workspace for a HOLO. I need to use a GUI to clone it. Heres what I have currently.

local Service = game:GetService("ServerStorage") local newModel = Service.FFA

script.Parent.MouseButton1Click:Connect(function()
newModel:clone() newModel.Parent = game.Workspace newModel.Position = Vector3.new(0,0,0) end)

If you know how to do this it would help me so much!

0
is this in a local or server script? Carvizal 25 — 6y
2
you need to put the model in replicated storage so the client can access it. User#5423 17 — 6y
0
Although the script is a bit clear,you should use Lua code blocks. rochel89 42 — 6y

1 answer

Log in to vote
2
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

In order to be able to do that upon a button click, you need to use Remote Events. Let me explain why.

If your script is a server script parented to a gui in StarterGui, it won't run when the gui is cloned, because the gui is cloned locally.

If your script is a localscript, it won't be able to access the ServerStorage.

Here's an example of what your scripts should look like:

Server script

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") --make sure to place the remote there

Remote.OnServerEvent:Connect(function(plr)
    local model = game:GetService("ServerStorage"):WaitForChild("FFA"):Clone()
    model.Parent = workspace
    model:SetPrimaryPartCFrame(CFrame.new()) --sets the CFrame of the model to 0,0,0 relatively to its primary part. Make sure to set the primary part in its properties!!!!
end)

Localscript

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
    Remote:FireServer()
end)

Note that it's an example. It's so that you get the idea of how it should work, and make your own code basing on it, along with some checks so for example exploiters cannot loop clone the model to workspace with the remote.

0
Actually a localscript can access server storage but it won't see the contents inside User#24403 69 — 6y
0
Same thing Amiaa16 3227 — 6y
Ad

Answer this question