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