Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a GUI button move clone then move a part?

Hello there, I'm trying to make a GUI that will clone a part in ServerStorage then move it to Workspace. For some weird reason, it just says "TestPart is not a valid member of ServerStorage".

Here's my script(It's a local script in the button):

script.Parent.MouseButton1Click:Connect(function()
	local storage = game:GetService("ServerStorage")
	local part = storage["TestPart"]:clone() -- Change "Part" to the part name.
	part.Parent = game.Workspace
end)

1 answer

✓ Accepted answer

Client-Server separation


This is because the client can't access anything in ServerStorage or ServerScriptService, for safety purposes, what you should do is use a remote event to communicate between client and server, like such

Client Side:

local Remote = game.ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Click:Connect(function()
	Remote:FireServer()
end)

ServerSide:

local Remote = game.ReplicatedStorage.RemoteEvent
Remote.OnServerEvent:Connect(function(plr)
	local storage = game:GetService("ServerStorage")
	local part = storage.TestPart:Clone()
	part.Parent = workspace
end)

Remote events, in general, should be put inside ReplicatedStorage, which, unlike ServerStorage, replicates to the client.


Links


For more info on remotes, try looking at these links:

Remote Events api-reference page

Remote functions and events

Hopefully this helped!

6 comments

0

So do I put that in 1 local script???

1

The client side script

0

I mean do I put both of the code in 1 local script in the button?

0

I think I know what to do.

0

put the client side code where you had your local script, and put the server side code in a server script (prefereably in server script service)

0

Thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.