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

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

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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!

0
So do I put that in 1 local script??? GodsGraceSavesAll 6 — 5y
1
The client side script theking48989987 2147 — 5y
0
I mean do I put both of the code in 1 local script in the button? GodsGraceSavesAll 6 — 5y
0
I think I know what to do. GodsGraceSavesAll 6 — 5y
View all comments (2 more)
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) theking48989987 2147 — 5y
0
Thank you. GodsGraceSavesAll 6 — 5y
Ad

Answer this question