code:
game.ReplicatedStorage.Events.HandTo.OnServerEvent:Connect(function(player) local co = player.Backpack.Tool:Clone() local Playertogive = game.Players:FindFirstChild(player.PlayerGui.ScreenGui.TextBox.Text) co.Parent = Playertogive Playertogive.Tool.Parent = Playertogive.Backpack print("Moved!") player.Backpack.Tool:Destroy() end)
error: ServerScriptService.Script:5: attempt to index nil with 'Tool'
when a player types something in a TextBox, it doesn't replicate to the server
you need to send the text as an argument to the RemoteEvent
also, reading from or editing guis on the server in general is kind of extremely nasty
-- somewhere in your localscript... game.ReplicatedStorage.Events.HandTo:FireServer(path.to.textbox.Text) -- server script game.ReplicatedStorage.Events.HandTo.OnServerEvent:Connect(function(player, text) local tool = player.Backpack.Tool:Clone() local playerToGive = game.Players:FindFirstChild(text) -- inconsistent variable casing is Not Good if playerToGive then tool.Parent = playerToGive player.Backpack.Tool:Destroy() end end)
If the player doesn't exist or if the user spelt it wrong it can break the script. Adding a simple if statement can help!
game.ReplicatedStorage.Events.HandTo.OnServerEvent:Connect(function(player) local co = player.Backpack.Tool:Clone() local Playertogive = game.Players:FindFirstChild(player.PlayerGui.ScreenGui.TextBox.Text) if Playertogive then co.Parent = Playertogive Playertogive.Tool.Parent = Playertogive.Backpack print("Moved!") player.Backpack.Tool:Destroy() else print("Player Not Found") end end)