Attempt to index nil with 'FindFirstChild"

local plr = game:GetService("Players").LocalPlayer
local backpack = plr:FindFirstChild("Inventory")

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	if backpack.Soul.Value > 50 then
		backpack.Soul.Value = backpack.Soul.Value - 50
		script.Parent.Parent.Transparency = 1
		script.Parent.Parent.CanTouch = true
	elseif backpack.Soul.Value <= 49 then
		plr.StarterGui.Notenoughsoul.Frame.Visible = true
		wait(10)
		plr.StarterGui.Notenoughsoul.Frame.Visible = false
	end
end)

Trying to make a portal that will open for resource(soul)
This gives me error attempt to index nil with findfirstchild.
Anyone can help pls?

If it’s nil that means you’re trying to get the localplayer from the server, put the backpack line in the Triggered event and change plr to player, and then get rid of the local plr line

Edit: And do the same for the other lines of code, reference the player that Triggered gives, also players don’t have a StarterGui in them, they have a PlayerGui

1 Like