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:
Create a server Script, and make sure that it’s a child of the ImageButton/TextButton
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:
Create a server Script, and make sure that it’s a child of the ClickDetector
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:
Create a server Script, and make sure that it’s a child of the ProximityPrompt
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)