Attempt to index nil with 'findfirstchild'

  1. What do you want to achieve? Keep it simple and clear!
    I want to make that if you are holding a pickaxe tool you can activate a proximity prompt
  2. What is the issue? Include screenshots / videos if possible!
    its says "attempt to index nil with find first child
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried looking for people with similar problems in the devforum but there are none

here is the code

local prox = script.Parent
local rs = game:GetService("ReplicatedStorage")
local crystal = rs:WaitForChild("Crystal")
local isCooldown = false


local playerData = require(game.ServerScriptService.PlayerData)
local player = playerData.GetPlayer()

	isCooldown = true
	prox.Enabled = false
	script.Parent.Parent.Transparency = 1
	script.Parent.Parent.CanCollide = false
	crystal:Clone().Parent = player.Backpack
	isCooldown = false
	prox.Enabled = true
	script.Parent.Parent.Transparency = 0
	script.Parent.Parent.CanCollide = true

while wait(1) do
	local pickaxe = player.Character:FindFirstChild("Pickaxe") -- here is the error
	if pickaxe then
		if isCooldown ~= true then
			prox.Enabled = true
			prox.Enabled = false

i use a module script to get the player from the server side, i have also other scripts that uses the module script but they are working perfectly fine. i tried printing the character and it also works fine. its only here that there is a problem. also just to let you know this is a singleplayer game, so the max people in each server is 1.

1 Like

This means the player’s character does not exist. Try adding a statement that waits for the player’s character to be added/exist before checking if the Pickaxe is inside it.


Thanks for the help, the code works now!