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

Attempt to index nil with FindFirstChildWichIsA?

Asked by 4 years ago

I want to make a custom key to drop tools, and everything works fine on the ClientSide of things and an event is fired, but the actual serversided drop script seems to not work, I can't find why, I tried to make char's "Archivable" value true but it gave a different error, here take a look.

local dropEvent = game.ReplicatedStorage.DropEvent

function onPlayerAdded(plr)
    local char = plr.Character

    local function dropItem()
        local tool = char:FindFirstChildWhichIsA("Tool")
        tool.Parent = game.Workspace
    end
    dropEvent.OnServerEvent:Connect(dropItem)
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

The output was: ServerScriptService.Script:7: attempt to index nil with 'FindFirstChildWhichIsA'

Help would be appreciated, thanks.

0
I had the same error at one point, the character prob hasn't loaded yet iirc Clorize 31 — 4y

1 answer

Log in to vote
1
Answered by
synkrio 281 Moderation Voter
4 years ago

The character hasn't loaded yet. Fix this with

local char = player.Character or player.CharacterAdded:Wait()
0
Thanks dude, helps a lot. TheOnlineItalian213 99 — 4y
Ad

Answer this question