Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why do I keep getting this error in this touched script?

function verifyAccess2(plyer2)
  
    for i = 1, #tools, 1 do 
	local s = game.Players:GetPlayerFromCharacter(plyer2)
	print(s.Parent.Name)
        if plyer2.Backpack:FindFirstChild(tools[i]) then
		
          return(true)
        end
    end
  
  return(false) --- doesn't look right, but try running one more time. Want to double check.
  
end

-- eror


Backpack is not a valid member of Model 00:53:12.373 - Stack Begin 00:53:12.374 - Script 'Workspace.TicketDoor.Script', Line 21 - global verifyAccess2 00:53:12.375 - Script 'Workspace.TicketDoor.Script', Line 37 00:53:12.375 - Stack End

1 answer

plyer2 is the character, not the player.

On line 4, you define the player. The backpack is a member of the Player, not the character.

function verifyAccess2(plyer2)
	
	local s = game.Players:GetPlayerFromCharacter(plyer2)
	for i = 1, #tools, 1 do 
		if s.Backpack:FindFirstChild(tools[i]) then
			return true;
		end
	end
	return false;
end
I also moved where you define the Player because no use defining it in a loop multiple times. You might also want to check if the player exist. i.e, if s then

Good Luck!

If I helped, please don't forget to accept my answer.

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