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

How can I use a RemoteEvent to give a tool to a player who interacts with a GUI?

I'm attempting to create a GUI menu where interacting with one of the various buttons gives the player a tool with all of its children and scripts and such. Here's the code I've been using so far:

local button = script.Parent
local tool = game.ReplicatedStorage("Fist Combat")
local plr = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
     tool:Clone().Parent = plr.Backpack
end)

This works fine for giving the player the tool upon interacting with the GUI however it doesn't contain any of the children that are found in the ReplicatedStorage of the tool.

Is there a way to recreate this process with RemoteEvents? I've been told RemoteEvents is the main solution to also give the children of the tool however any solution that should allow the tool and its children in the same GUI press would be helpful.

Thanks for reading, any insight on what I might be able to do is helpful.

1 answer

✓ Accepted answer

Try this!

Run this in Command Prompt( the thing in the bottom that says run a command ):

local Folder = Instance.new("Folder") Folder.Name = "Events" Folder.Parent = game:GetService("ReplicatedStorage" )local Remote = Instance.new("RemoteEvent") Remote.Parent = Folder  Remote.Name = "Toolgiver"

^^ This adds a Folder and a Remoteevent into ReplicatedStorage

Put this in a Script in ServerScriptService:

-- ReplicatedStuff
local Rep = game:GetService("ReplicatedStorage") -- gets ReplicatedStorage
local Remote = Rep.Events.Toolgiver -- The Toolgiver remote
-- Function
Remote.OnServerEvent:Connect(function(Player,Tool) -- registers signals by clients
	local Clone = Tool:Clone() -- Clones the tool
	Tool.Parent = Player.Backpack -- Sets parent of tool to backpack
end)

Put this in the Button localscript:

-- ReplicatedStuff
local Rep = game:GetService("ReplicatedStorage") -- gets ReplicatedStorage
local Remote = Rep.Events.Toolgiver -- The Toolgiver remote
local tool = Rep:FindFirstChild("Fist Combat") -- gets the tool
-- Guistuff
local button = script.Parent
local plr = game.Players.LocalPlayer
-- Function
button.MouseButton1Click:Connect(function() -- register Mousebutton1Click
	Remote:FireServer(tool) -- gives the tool that will be cloned on the server
	-- The Remote will send information to the Server, Player and Tool
end)

The explanation is inside the script.

2 comments

1

Thanks, I tested this out and it works wonderfully. I'm very grateful for your help.

0

No problem! Would appreciate when you don't forget to accept my answer. :)

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