Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to index nil with 'FindFirstChild'?

hi, so basically i'm having this problem (title), and i do not understand what is wrong. i'm using a remote event (FireServer) to destroy a part (in workspace) that spawns. code:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	local waa = game.Players.LocalPlayer:FindFirstChild("NicePartlol")
	wait()
	waa:Destroy()
end)

1 answer

✓ Accepted answer

You can use the player parameter for the event 'OnServerEvent'. Since this is a ServerScript, you cannot state the LocalPlayer.

You can replace the variable by doing this:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    local waa = player:FindFirstChild("NicePartlol")
    wait()
if waa =~ nil then
    waa:Destroy()
end
end)

3 comments

0

thank you!

0

wait, now destroy has index nil.

0

You should check if waa is nil or not

This discussion is preserved as it was. New answers, comments, and votes are closed.