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.

01local dropEvent = game.ReplicatedStorage.DropEvent
02 
03function onPlayerAdded(plr)
04    local char = plr.Character
05 
06    local function dropItem()
07        local tool = char:FindFirstChildWhichIsA("Tool")
08        tool.Parent = game.Workspace
09    end
10    dropEvent.OnServerEvent:Connect(dropItem)
11end
12 
13game.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

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

Answer this question