Attempted to Index nil with 'parent', when clearly defined

I want the character’s inventory contents that was transfered to “FakeBackpack” beforehand, (that part of the script functions well.) to return to the Player’s backpack. However, I keep getting this error: "

https://gyazo.com/0e082d4b414a56d20eb8a3cba1c30bbc

I’ve looked up solutions and one of them said that their script did not define the right thing, I’ve looked in the script and I don’t see anything out of the normal.

Note: I am not the smartest individual, so sorry if this post comes across as vague or stupid.

What I am trying to get is the character’s player, (which strangely it does when state == cuff) but shows an error in the output window, which I am assuming is the cause for this.
Script:

--[[

Made By Matthew_Plays55
Please do not delete the credits if you reupload. Thanks!

]]
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local TargetTorso = nil
local Using       = false
local sound = script.Parent:WaitForChild("Sound")



function CheckForTargetTorso(part)
	if part.Parent:IsA'Model' and part.Parent:FindFirstChildOfClass'Humanoid' then
		local char = part.Parent
		local torso
		if char:FindFirstChild'Torso' then
			torso = char.Torso
		elseif char:FindFirstChild'HumanoidRootPart' then
			torso = char.HumanoidRootPart
		end
		return char, torso
	end
end


	
function CheckForTorso(player)
	local Char = player.Character
	if Char:FindFirstChild'Torso' then
		return Char.Torso
	else 
		return Char.HumanoidRootPart
	end
end



RemoteEvent.OnServerEvent:Connect(function(player, state, part)
	
	
    local Character = game.Players:GetPlayerFromCharacter(part.Parent)
--above is the line that causes the error.
	if state == 'Cuff' then
		local target      = nil
		local playerTorso = nil
		
		target, TargetTorso = CheckForTargetTorso(part)
		playerTorso = CheckForTorso(player)
		
		if target then
			Using = true
			RemoteEvent:FireClient(player, 'Use')
			spawn(function()
				if Using then
					TargetTorso.Anchored = true	
					
					local hum = TargetTorso.Parent:WaitForChild("Humanoid")
					local FBK = TargetTorso.Parent:WaitForChild("FakeBackpack")
				    
					hum:UnequipTools()
					for _,v in pairs(Character.Backpack:GetChildren()) do
						v.Parent = FBK
					end
					local soundclone = sound:Clone()
					soundclone.Parent = TargetTorso
					soundclone.PlayOnRemove = true
					soundclone:Destroy()
				end				
				while Using and wait() do			
					TargetTorso.CFrame = playerTorso.CFrame * CFrame.new( 0, 0, -6.5 )
				end				
				
			end)			
			
		end
		
	
	elseif state == 'UnCuff'then
		
     	local target      = nil
		local playerTorso = nil
		
        TargetTorso.Anchored = false
        local FBK = TargetTorso.Parent:WaitForChild("FakeBackpack")
		local backpack = Character:WaitForChild("Backpack")
     	for _,v in pairs(FBK:GetChildren()) do
			    	v.Parent = backpack
			end
		Using = false	
		
		wait()

	end
	
end)

Local script it fires to

--[[

Made By Matthew_Plays55
Please do not delete the credits if you reupload. Thanks!

]]

local Player = game.Players.LocalPlayer
local Mouse  = Player:GetMouse()
local Tool   = script.Parent
local Using  = false
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")

Tool.Activated:Connect(function()
	if not Using then
		if Mouse.Target then
			RemoteEvent:FireServer('Cuff', Mouse.Target)
		end
	else 
		Using = false
		RemoteEvent:FireServer('UnCuff')
	end
end)

RemoteEvent.OnClientEvent:Connect(function( state )
	if state == 'Use' then
		Using = true
	end
end)

If you are confused, please let me know what I can do to help you understand.

EDIT: Forgotten to remove the “–” from the parts that don’t work, they should be fixed now.

Show us the LocalScript that the event is fired from

Crap, I pasted the wrong script. Hold on.

Alright I fixed it, should have the correct script now

that other script was not made by matthew, I pasted part of the original script with the wrong one

Maybe the object you are trying to index didn’t load, so try using the WaitForChild function

Could you put a comment in the line that it is causing the error?

I apologise, I was getting to it.

local Character = game.Players:GetPlayerFromCharacter(part.Parent)

Just do
local Character = player.Character
You already have the player from the onserverevent.

That is happening because part wasn’t even passed in the the :FireServer():

RemoteEvent.OnServerEvent:Connect(function(player, state, part)
RemoteEvent:FireServer('Cuff', Mouse.Target) / RemoteEvent:FireServer('UnCuff')
1 Like

Alright, so I’ve passed “part” in :FireServer()
Please tell me if I have interpereted it wrong

RemoteEvent:FireServer('Cuff', Mouse.Target, part) / RemoteEvent:FireServer('UnCuff', part)

I try that and the error still persists.

Thats not what you were supposed/suggested to do.

And my bad, i forgot to say that “part”, wasn’t even a thing!

Meaning that you would to somehow make it be a thing ;/.

1 Like

Shoot, that was all on my part. Apologies.

2 Likes

You never supplied the part as a Parameter:


So it’s going to index nil

1 Like

@shkip_not on the server you should check for a nil Parameter

1 Like

check if part exists before anything on server too, not just client

Use this code here:
image

1 Like

I wish I could mark more than one post as a solution, thank you all!

I’m making some changes to your code, because, bugs

Ehh, it’s okay. The handcuffs are a placeholder anyway.

1 Like