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?
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)