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

How do i put a part out of serverstorage when a textbutton is touched in a gui?

Asked by 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

So yeah, how do i do that??

0
Remote events. User#25115 0 — 5y
0
Can i have an example, please? kattenverzorger 23 — 5y

1 answer

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

This is a complete request, which isn't allowed, but I'm feeling nice. In the future, please do not post questions without showing your clear attempt at solving the issue.

To accomplish this, we'll have to make use of a few things:

Remote Events, Local Scripts, Server Scripts, TextButtons

The following code will assume you have a ScreenGui in the StarterGui service with a TextButton inside it. The LocalScript will be inside the TextButton. Additionally, I'm assuming you have an instance in ServerStorage named Part.

--Local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local button = script.Parent

button.MouseButton1Click:Connect(function()
   RemoteEvent:FireServer() --tell server to clone part into workspace
end)

Let's go through this line by line. First, we set up our variables. Our RemoteEvent variable is waiting for the server to add a remote event to ReplicatedStorage (see lines 5 and 6 of the next script). Our next variable, button, is the TextButton. When the player clicks this, the function connected to MouseButton1Click will be run. This tells the server to perform an action (line 8 of the Local script).

--Server script

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Parent = ReplicatedStorage

RemoteEvent.OnServerEvent:Connect(function(player) --first parameter is always the player that fired the event
   if ServerStorage:FindFirstChild("Part") then
      local part = ServerStorage.Part:Clone()
      part.Parent = workspace
   end
end)

In this script, we are creating the remote event in lines 5 and 6. This is what the client was waiting for previously. The function connected to OnServerEvent will be run once RemoteEvent:FireServer() is run in the Local script. Afterwards, we check if there is an object in ServerStorage named Part. If so, we create a clone of that and parent it to the workspace. Further reading is available below.

Resources:

Remote Events and Functions

MouseButton1Click


Accept and upvote if this helps!

1
Ok i am sorry i didnt know that wasn"t allowed kattenverzorger 23 — 5y
0
upvote if it helped Gey4Jesus69 2705 — 5y
Ad

Answer this question