Hello! I have been recently trying to make a hand-to system and I have a problem, here is basically how the system works: A Gui appears and the worker has in hand the item that they wan’t to give to the customers, and they type the name of the customer into the textbox. If the player is nil it will return a nil value, if its not it will give the customer the item, here are some screenshots:
-- # The script is in a local script
-- // VARIABLES \\ --
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
-- // MAIN CODE \\ --
script.Parent.Parent.HandToFrame:TweenSize(UDim2.new(0, 673,0, 65), "In", "Quint", 0.2)
wait(0.4)
script.Parent.Parent.HandToFrame.TextBox.Visible = true
if script.Parent.Parent.HandToFrame.TextBox.Text == Player.Name then
return Player.Name..false
else
for _,v in pairs(Player.Backpack:GetChildren()) do
v:Clone().Parent = game.Players:FindFirstChild(script.Parent.Parent.HandToFrame.TextBox.Text).Backpack
end
end
You’re getting the error because you’re trying to place the tool in the backpack of a player that doesn’t exist. Your use of FindFirstChild offers no benefit as you never check if it returned nil. It’s important to remember that changes you make on the client don’t replicate to the server too, so the other player will never actually receive the tool. You need to give the tool on the server. Also, if the code you provided is the full script, it only runs once. This means that even if the player enters a correct name the function won’t run.
TLDR:
Check if the player actually exists
Only run the function when the player interacts with the text box
Tell the server to give the tool using a remote event
In order for this to work you need to communicate with the server that you’re wanting to give another player a tool you have, therefore the server can then update it and it will replicate for the other user.
Secondly, you’re not checking if that player is in the server anymore.
EDIT: I didn’t see DarkContinuum’s post. I agree with everything stated.