Player Backpack Help
Hello! So I have a little issue here. Here is what I am trying to achieve: your team when you get in-game is neutral, but when you chat “:Team me Security” It will put you into the “Security” team. This much works. This is a LocalScript put in StarterPlayerScripts. Then in the same script, I have this code that will check if a player is added so then it can give them a keycard that gives them access to certain buildings/ through security.
teams:FindFirstChild("Police").PlayerAdded:Connect(function(player) print("Got Team") local PoliceKeycard = game.ReplicatedStorage:FindFirstChild("PoliceKeycard"):Clone() print("Cloned") PoliceKeycard.Parent = player.Backpack print("Gave Keycard") end)
This much works, when I test the game and say that, it puts a “PoliceKeycard” into my backpack. When I do Print(player.Backpack:GetChildren()), It prints everything in the backpack EXCEPT for the keycard. But then when I go into the backpack, it is there, so I do not know why it says it isn’t. Here is the code that is checking for the keycard. (also teams is a variable for teams = game:GetService(“Teams”))
local KeyCardCheckOne = game.workspace.KeyCardCheckOne KeyCardCheckOne.Touched:Connect(function(hit) local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) if player then print(player.Backpack:GetChildren()) if player.Backpack:FindFirstChild("PoliceKeycard") or player.Character:FindFirstChild("PoliceKeycard") then print("You have the keycard. You may Pass") else print("You Do not have the keycard. You may not pass.") end end end)
When I do not have the keycard, it prints I don’t have it. When I team myself police and I can see it in my backpack, it still says it isn’t there. Also, I put the “or” because when a tool is equipped it goes into the Character.
So can anyone help me with this? What am I doing wrong?