Can't find player

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I would like to be able to get the player

  2. What is the issue? Include screenshots / videos if possible!
    I get the following error: attempt to index nil with 'Backpack'
    Code:

local Players = game:GetService("Players")
--Function
local function Clicked(Giocatore)
	local player = Players:FindFirstChild(Giocatore.Name)
	local Tool = player.Backpack:FindFirstChildOfClass("Tool") or Giocatore:FindFirstChildOfClass("Tool")
end
Part.Touched:Connect(Clicked)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Found nothing online
local Players = game:GetService("Players")
--Function
local function Clicked(Giocatore)
	local player = Players:GetPlayerFromCharacter(Giocatore.Parent)
    if player then
       	local Tool = player.Backpack:FindFirstChildOfClass("Tool") or Giocatore:FindFirstChildOfClass("Tool")
    end
end
Part.Touched:Connect(Clicked)
3 Likes

@canyoumakemeinavideo
Thank you a lot, it works!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.