Answered by
5 years ago Edited 5 years ago
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:
01 | local Players = game.Players |
02 | local Player = game.Players.LocalPlayer |
03 | local Button = script.Parent |
04 | local RemoteEvent = game.ReplicatedStorage.RemoteEvent |
07 | Button.MouseButton 1 Click:Connect( function () |
09 | local TextBox = Player.PlayerGui:WaitForChild( "ScreenGui" ):WaitForChild( "TextBox" ) |
11 | local FoundPlayer = Players:FindFirstChild(TextBox.Text) |
14 | RemoteEvent:FireServer(FoundPlayer, Button.Name) |
Server Script:
01 | local RemoteEvent = game.ReplicatedStorage.RemoteEvent |
03 | RemoteEvent.OnServerEvent:Connect( function (player, FoundPlayer, ButtonName) |
05 | if ButtonName = = "Name" then |
06 | local Item = game.ReplicatedStorage.Item |
07 | Item:Clone().Parent = FoundPlayer:FindFirstChild( "Backpack" ) |
08 | elseif ButtonName = = "OtherName" then |
09 | local Item = game.ReplicatedStorage.OtherItem |
10 | Item:Clone().Parent = FoundPlayer:FindFirstChild( "Backpack" ) |