So, I have a gui that has a textbox, and when a players name is put onto the textbox and a button is clicked they receive a specific item, any idea on how I can do this?
✓ ANSWER ACCEPTED
How can I make a tool giver GUI like a trolling GUI?
1 answer
✓ Accepted answer
You can do this with FindFirstChild(). Basically if we use FindFirstChild() then add the TextBox.Text into the "()" we are trying to Find the Child that has a name of the TextBox's Text.
First add a RemoteEvent into ReplicatedStorage, we will be firing this from the Local Script to then give the player the item.
Then add a Local Script to your Button.
Next add a Server Script into ServerScriptService.
Then add the following code: (You will probably need to change these locations inside the scripts to wherever your stuff is located.)
Local Script:
local Players = game.Players
local Player = game.Players.LocalPlayer
local Button = script.Parent
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
Button.MouseButton1Click:Connect(function()
local TextBox = Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("TextBox")
local FoundPlayer = Players:FindFirstChild(TextBox.Text)
if FoundPlayer then
RemoteEvent:FireServer(FoundPlayer, Button.Name)
end
end)
Server Script:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(player, FoundPlayer, ButtonName)
if ButtonName == "Name" then
local Item = game.ReplicatedStorage.Item
Item:Clone().Parent = FoundPlayer:FindFirstChild("Backpack")
elseif ButtonName == "OtherName" then
local Item = game.ReplicatedStorage.OtherItem
Item:Clone().Parent = FoundPlayer:FindFirstChild("Backpack")
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

46 comments
Hey so, my texbox and all that are in a Frame, any modifications I need to do?
You'll just need to change the variable locations. So if the Textbox and the Button are in the same frame then you'll need to change both their Variables in the local script and just add a :WaitForChild("Frame") then the button, textbox, etc.
Should look like this: Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame"):WaitForChild("TextButton") -- Do the same with the TextBox. Also change ScreenGui to your ScreenGui's Name.
I suppose they all don't need to be :WaitForChild() but I do it just in case. As for the server script, you'll just need to change the variable location to where the item is you want to give the player.
If you get any errors just let me know. I'll help you solve it.
Also, there are multiple buttons.
Multiple Buttons?
Yes, multiple buttons, one gives a sword, another gives a gun etc.
Ah okay.
I mean, you could add a Folder into ReplicatedStorage holding all your RemoteEvents and call them "GiveSword", "GiveGun", etc. and do the same thing with the Server Scripts, and name the Scripts the same, then just change the item you want to give the player.
Oh, so a script for each item?
You'll also want to add a local script to each Button aswell, then change the RemoteEvent variable to the RemoteEvent to want to fire, so if the button you want to click on is going to give the player a sword, get the RemoteEvent called "GiveSword" or whatever you named it.
Yeah a script for each item. There might be a better way though, I'll look into it.
Okay, nevermind I've found a better way. I'll edit my code above. Basically you can check if the ButtonName is equal to "Item".
Edited the code.
I have 3 buttons, so do I do elseif for the other one?
Yes
Also just note that if you're going to put the actual Item name in the speech marks then the ButtonName has to be that name, otherwise it wont work, I guess it doesn't have to be the item name, you could also say, if ButtonName == "GiveItemSwordButton" or whatever your Button names are then it will still give the player that item.
You just gotta make sure that the ButtonName is indeed equal to what you're putting in the speech marks.
Hey so how can I make the event give the item
It's in the Server Script. Where the "local item" is, change the location to where the Item is, is it inside a folder inside ReplicatedStorage, ServerStorage? If it's in ReplicatedStorage then do local item = game.ReplicatedStorage.Items.Item -- Items is the folder that the Item is stored in, change "Item" to item you want to clone.
Then we are cloning it into the Player's Backpack.
If you also want the Player to still have that item when they reset their character, clone it into their StarterGear aswell.
I get an error in the output saying : " ServerScriptService.Script:3: attempt to call a userdata value"
Could you edit your question and add the code or put it on pastebin and send me the link so I can view your code?
https://hastebin.com/lefifajeyi.sql
Okay..
Try this: https://hastebin.com/corizagoke.bash I've edited the code and made the variables to what you had. Let me know if it doesn't work.
I messed up a bit of the code, I've updated the link.
hey so uhm i was making the local script for each one and i dont know which remote event to use, do i just put all the tools in 1 remote event?
The Tools don't have to be in the RemoteEvent. You only need 1 RemoteEvent for this to work, put the RemoteEvent into ReplicatedStorage and if you want to put the Tools into it you can, but I wouldn't do this, I'd add a folder into ReplicatedStorage and name it Items and add the Tools into it.
and how would I need to modify the code?
All you need to do is change the item variable in the Server Script, if you've created a Folder into ReplicatedStorage and named it "Items" and put the Tools into it then you can just copy this: https://hastebin.com/ejejazaxuw.bash
My bad, I forgot to change the RemoteEvent Variable in the Server Script. https://hastebin.com/xiwehuzawe.bash
Let me know if it works or not
I doesn't work, I get this error in the output: " RemoteEvent is not a valid member of ReplicatedStorage" I put the tools in a folder named Items in replicatedstorage
Where is your RemoteEvent located?
i dont have one, in the one you gave me there is still a remote event.
You need to add a RemoteEvent into ReplicatedStorage. Add a RemoteEvent into ReplicatedStorage and then see if it works.
where should the remove event be? like a parent of the Items folder or an Item?
It should be inside of ReplicatedStorage, it's Parent needs to be ReplicatedStorage
"MouseButton1Click is not a valid member of Frame" thats the error i get, the local script is just in the frame.
The local script needs to be in the buttons, each button should have the local script.
Your explorer should look something like this: https://gyazo.com/48a5d0f563a9c92054289ae10830c82e
Let me know if it works or not.
Thank you alot, it works.