CurrentScannedPlayer is not a valid member of Part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Getting rid of this error
  2. What is the issue? Include screenshots/videos if possible!
    When I click to fire the ClickDectector in the Part, it gives me this error for both buttons:
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried fixing it by adding in:

local CurrentScannedPlayer = script.Parent.Parent.Parent:WaitForChild("CurrentScannedPlayer")

But it didn’t fix it, I even fixed the Parent in the scripts.
Script 1:

local DB = false
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	if Player.TeamColor == BrickColor.new("Bright red") then
		if DB == false then
			DB = true
			local CurrentScannedPlayer = script.Parent.Parent.Parent:WaitForChild("CurrentScannedPlayer")
			game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("BorderControl"):FireAllClients("RIGHTDOOR","Open")
			local P = game.Players:FindFirstChild(script.Parent.CurrentScannedPlayer.Value)
			game:GetService("ReplicatedStorage"):WaitForChild("Remotes").ShowNotif2:FireClient(P,"BORDER","You have successfully crossed!")
			for i,v in pairs(game.Workspace["Border Controls"].Screen.SurfaceGui.ScrollingFrame:GetChildren()) do
				if v:IsA("TextLabel") and v.Name ~= "EX" then
					v:Destroy()
				end
			end
			script.Parent.Parent.Parent.CurrentScannedPlayer.Value = "None"
			wait(2.5)
			DB = false
		end
	end
end)

Script 2:

local DB = false
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	if Player.TeamColor == BrickColor.new("Bright red") then
		if DB == false then
			DB = true
			local CurrentScannedPlayer = script.Parent.Parent.Parent:WaitForChild("CurrentScannedPlayer")
			local P = game.Players:FindFirstChild(script.Parent.CurrentScannedPlayer.Value)
			local Character = P.Character
			Character.HumanoidRootPart.CFrame = script.Parent.Parent.Parent.BACKTP.CFrame
			game:GetService("ReplicatedStorage"):WaitForChild("Remotes").ShowNotif2:FireClient(P,"BORDER","You have denied access!")
			for i,v in pairs(game.Workspace["Border Controls"].Screen.SurfaceGui.ScrollingFrame:GetChildren()) do
				if v:IsA("TextLabel") and v.Name ~= "EX" then
					v:Destroy()
				end
			end
			script.Parent.Parent.Parent.CurrentScannedPlayer.Value = "None"
			wait(2.5)
			DB = false
		end
	end
end)

Hiearchy:

Try using doing an nil check:

local CurrentScannedPlayer = script.Parent.Parent.Parent:FindFirstChild("CurrentScannedPlayer")

if CurrentScannedPlayer then
    --Code
end

It’s on the image I’ve shown on top, it’s the Script that’s in the SP Part.

1 Like

Are you sure? This was not supposed to happen, maybe the script you shown is an script under the child of the SurfaceGui.

No, the Border control is a Model located in the Workspace.

Ok… Right click on one of the scripts that has the code you shown, and click at “Show in explorer”.

Alright, then try doing the nil check as i said in the first reply.

Still returns:

After I clicked on the button.

Try printing:

print(script.Parent)
print(script.Parent.Parent)
print(script.Parent.Parent.Parent)

Prints out nothing I think, and it doesn’t show up the error when I press the button.

I think i found the issue:

local P = game.Players:FindFirstChild(script.Parent.CurrentScannedPlayer.Value)

Use this instead:

local P = game.Players:FindFirstChild(CurrentScannedPlayer.Value)

If the code above doesn’t works, use this:

local P = game.Players[CurrentScannedPlayer.Value]-- The "CurrentScannedPlayer" must be an StringValue.

https://developer.roblox.com/en-us/api-reference/property/Player/Character

Initially, this property is nil then set when the player’s character first spawns. Use the Player.CharacterAdded event to detect when a player’s character properly loads

Those two errors are coming from separate scripts, not 2 errors in 1 script.

Yes, i know about that, i wonder how did you even thought that i was currently caring about the second error.

Actually, there are 2 errors coming from 1 script.

No, when I click the Deny button, it gives the attempt to index nil with ‘Character’ and I did a little bit of research and accordingly, I have to put it into a LocalScript instead. The FireClient error is coming when I hit the Accept button.

What you want me to help you with now?

If I put the script into a LocalScript, it breaks everything.

FOR THE ERROR thats saying, "Attempting to index nil with ‘Character’