Attempt to index nil with 'FindFirstChild' error

Hello my code gives this error: ‘‘attempt to index nil with ‘FindFirstChild’ error’’, i looked up some solutions but it didn’t work can somebody help me the script gives me the error on second line of code:

script.Parent.RebirthTycoon.Event:Connect(function(player)
	local tycoon = player:FindFirstChild("TycoonOwned").Value
	local clone = game.ServerStorage:FindFirstChild(tycoon.Name):Clone()

	clone.Parent = tycoon.Parent
	clone.Values.OwnerValue.Value = tycoon.Values.OwnerValue.Value
	player.TycoonOwned.Value = clone
	clone.MainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tycoon.MainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text
	tycoon:Destroy()

	player:FindFirstChild("leaderstats").Rebirths.Value += 1
end)
1 Like

This is because you’re trying to call :FindFirstChild on nil. This is probably caused on line 2, the player argument is probably nil

how can i fix it tho, im trying to find the player and then find the tycoon owned value.

check if the player is nil before running the code, and if it isn’t stop the function.

.Event:Connect(function(player)
    if (not player) then
        warn("No player argument passed in event RebirthTycoon")
        return -- this will stop the function
    end
-- rest of the code

it says this in the output:

No player argument passed in event RebirthTycoon - Server - Rebirth:3

and also no rebirths get added in the leaderstats:
image

Then the issue is that you aren’t correctly supplying the “player” parameter, could you show us where you fired the event?

Then whatever is firing the bindable event is not passing the player argument. Could you show the part that is firing the bindable

I think you meant where is the event located its located in workspace and in
image

No, what I meant is where is the script where you are firing the bindable event using :Fire(), because you arent correctly giving it the player parameter

its in this script
image

can you show the code in the script

Where are you calling the event from?

show us the code snippet of where you fired the event, and what parameters you’re supplying it with

The fire line:

elseif v:FindFirstChild('Rebirth') and v:FindFirstChild('Rebirth').Value then
									if player:FindFirstChild('leaderstats').Cash.Value >= v.Price.Value then
										playSound(v, audio.Rebirth.SoundId)
										player.leaderstats.Cash.Value -= v.Price.Value
										objects[v.Object.Value].Parent = tycoon.Purchases
										tycoon.Parent:FindFirstChild('RebirthTycoon'):Fire()
										v:Destroy()

You aren’t passing the player as an argument, try :Fire(player)

1 Like

You are not passing the player argument, since you’re using a bindable event and not a remot event the player argument is not there by default

2 Likes

Both of your solutions worked, thank you two so much

1 Like

No problem, just keep in mind bindable events don’t pass anything by default

1 Like

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