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

attempt to index field 'Parent' (a nil value) - How do I fix? [closed]

Asked by 5 years ago
Edited 5 years ago
23:00:32.202 - Workspace.Model.Scan.Scan.Script:40: attempt to index field 'Parent' (a nil value)
23:00:32.203 - Stack Begin
23:00:32.203 - Script 'Workspace.Model.Scan.Scan.Script', Line 40
23:00:32.203 - Stack End

Here's the part of the code, it works by a player touching a brick.

Door = script.Parent

Inf = "Red Spawn"

Cantouch = onTouched == true

function onTouched(hit) 
        Cantouch = false
        print("Scan hit") 
        local human = hit.Parent:FindFirstChild("Humanoid") 
        script.parent.parent.Display.SurfaceGui.NAME.Text = hit.Parent.Name
        if (human ~= nil ) then
                if game.Players:playerFromCharacter(hit.Parent).TeamColor == game.Teams:findFirstChild(Inf).TeamColor then
                    script.parent.Parent.Display.SurfaceGui.Infected:play()
                    script.parent.Parent.Infected.Transparency = 0
                    script.Parent.Parent.Display.SurfaceGui.INFECTED.Visible = true
                    Cantouch = false
                end
0
either "hit" is "game" or its nil Gey4Jesus69 2705 — 5y
0
Do you have more to share? The problem seems to lie outside of this one line as 'hit' doesn't have a parent. xPolarium 1388 — 5y
0
Please post the (whole) script in your answer so that we may better assist you SerpentineKing 3885 — 5y
0
Give us more lines of code RetroGalacticGamer 331 — 5y
0
Sorry, updated it TheBlue_Hood -5 — 5y

Closed as Non-Descriptive by DeceptiveCaster and Gey4Jesus69

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Well, until you actually put the full script up, I will give my suggestion on how to fix this. Since the error is found on Line 40 you only need to edit this line in your code.

Since the error is that the parent is nil, this means you most likely have too many .Parent in the line, unless the variable was predefined, in which case the error is actually located on the line of the local variable.

The easiest solution to try is to just start removing .Parent from the line until it isn't nil. Please check your parenting of whichever object is being called.

Ad