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'?

for i, v in pairs(game.Workspace:GetChildren()) do
		        local v = (v: IsA("Model") and v) or nil
        if Character and v:FindFirstChild("HumanoidRootPart") and (Character.HumanoidRootPart.Position - v.HumanoidRootPart.Position).magnitude <= range then

I am very new to scripting, this is a portion of my combat script.

3 comments

0

Can you please show us the whole script?

0

Are you trying to get the distance between a player and a npc?

0

@Official_DuckyYT I cannot post it as it is too long

2 answers

✓ Accepted answer

Its giving that error because of

v: IsA("Model")

When its not a model it would be nil and your settings v to that so when you do this

v:FindFirstChild("HumanoidRootPart")

It is attempting to use FindFirstChild() on nil which would error.

SOVLED! I WAS MISSING AN ENTIRE LINE OF CODE, I WON'T POST IT BECAUSE IT IS GAME SPECIFIC AND THE ISSUE HAD LITERALLY NOTHING TO DO WITH THIS ERROR SO IT WOULD ONLY CONFUSE PEOPLE!

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