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