Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to index nil with 'FindFirstChild'?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
0
thank you! Realbluedrago 8 — 4y
0
wait, now destroy has index nil. Realbluedrago 8 — 4y
0
You should check if waa is nil or not CrypxticDoge 135 — 4y
Ad

Answer this question