Detect a tool in a players backpack upon equipping another tool

So, I’m trying to make a tool that gets deleted upon equipping if 2 other conditions are met. The conditions being:

  • The player having another tool called “Bing Helper” in their backpack
  • A certain number on a random number generating board is the same as the number on the tool

What’s the issue
It just doesn’t work as I expected it to

What have I tried

local ticket = script.Parent
local numBing = game.Workspace["RandomBoards"].BingBoard.SurfaceGui.TextLabel
local numTicket = script.Parent.Handle.SurfaceGui.TextLabel

ticket.Equipped:Connect(function(plr)
	wait(0.2)
	if plr:FindFirstChild("Backpack"):FindFirstChild("Bing Helper") and numTicket.Text == numBing.Text then
		ticket:Destroy()
    else
        return
	end
end)

From this it just gives me this error in the output:

Workspace.Lost_Cabrexada.Number Ticket.Script:9: attempt to index nil with 'FindFirstChild'
1 Like

ticket.Equipped:Connect(function(plr)

plr is not player, the value passed trough Tool.Equipped is actualy PlayerMouse, also can be gotten by LocalPlayer:GetMouse()

so “Backpack” cannot be found inside PlayerMouse

a solution for your problem should be this:

local ticket = script.Parent
local numBing = game.Workspace["RandomBoards"].BingBoard.SurfaceGui.TextLabel
local numTicket = script.Parent.Handle.SurfaceGui.TextLabel

ticket.Equipped:Connect(function(Mouse)
	wait(0.2)

	local Player = game.Players:GetPlayerFromCharacter(ticket.Parent)
	if Player then else return end

	if Player.Backpack:FindFirstChild("Bing Helper") and numTicket.Text == numBing.Text then 
		ticket:Destroy()
	end
end)
1 Like

instead of getting the players from the parameter wich is actually a mouse. you should get the parent of the tool. as this is always the players character when equipped.

1 Like

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