Server Storage to Workspace

Hello!

  1. I am trying to create a button that will move a model from server storage into workspace, and vice versa.

  2. I have tried to replicate and clone it, but not sure how to make a script that will solve this

  3. I have searched throughout Devforum and developer hub, but can’t find a solution to what I’m trying to do.

can you provide your script?

here are the two basic steps.

  1. Button will send a remote event to the server

  2. The server script will receive the remote and clone then parent the part to workspace

I’ve got a script to move it, but not sure how to make one that moves it back and forth, with the click of a button.

local map = game.ServerStorage.Obby
map.Parent = game.Workspace

This is a simple way to move the model back and forth. (Make sure to add a RemoteEvent inside of ReplicatedStorage)

LocalScript (put this script inside of your button)

script.Parent.MouseButton1Click:Connect(function()
	if game.Workspace:FindFirstChild("Obby") then
		game:GetService("ReplicatedStorage").RemoteEvent:FireServer("ServerStorage")
	else
		game:GetService("ReplicatedStorage").RemoteEvent:FireServer("Workspace")
	end
end)

Server Script (put inside of ServerScriptService)

local ServerStorage = game:GetService("ServerStorage")
local Map = ServerStorage.Obby

game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(Player, ParentName)
	print(ParentName)
	
	if ParentName == "ServerStorage" then
		Map.Parent = ServerStorage
	else
		Map.Parent = game.Workspace
	end
end)

Since server scripts can run when used in GUIs, there’s no need to use RemoteEvents or RemoteFunctions to achieve what you’re looking for. All you need to do is:

  1. Create a server Script, and make sure that it’s a child of the ImageButton/TextButton
  2. This will need to be the script’s code:
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")

local button = script.Parent

local obby = ServerStorage.Obby

button.MouseButton1Click:Connect(function()
	obby.Parent = if obby.Parent == ServerStorage then Workspace else ServerStorage
end)

If the button is a BasePart rather than a GUI, then the script’s code will depend on whether you wish to use a ClickDetector or a ProximityPrompt

If you’re using a ClickDetector:

  1. Create a server Script, and make sure that it’s a child of the ClickDetector
  2. This will need to be the script’s code:
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")

local clickDetector = script.Parent

local obby = ServerStorage.Obby

clickDetector.MouseClick:Connect(function()
	obby.Parent = if obby.Parent == ServerStorage then Workspace else ServerStorage
end)

And if you’re using a ProximityPrompt:

  1. Create a server Script, and make sure that it’s a child of the ProximityPrompt
  2. This will need to be the script’s code:
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")

local proximityPrompt = script.Parent

local obby = ServerStorage.Obby

proximityPrompt.Triggered:Connect(function()
	obby.Parent = if obby.Parent == ServerStorage then Workspace else ServerStorage
end)
1 Like
Item = game.ServerStorage.ItemName
ItemClone = Item:Clone()
ItemClone.Parent = game.Workspace