I have a door whereas when a Player on the team Police touches the door, it will open. I have the opening script done, but for the game to check if the Player is on the Police team is failing. I have some code snippets for it
First, the Variables:
--Vaiables local Sensor = script.Parent.Sensor local Door = script.Parent["Prison Side Door 1"] local Window = script.Parent.Window local PlayerV = game.Workspace:FindFirstChild("Head") local Light = script.Parent.Light local Sensor = script.Parent.Sensor local db = true local Police = game:GetService("Teams"):FindFirstChild("Police")
Then the function that runs when the Sensor is touched:
--Function for everything local function Everything(part) local plr = game.Players:GetPlayerFromCharacter(part.Parent) local hum = part.Parent:FindFirstChild("Humanoid") print('found humanoid') if hum then local Player = part.Parent local Character = workspace:WaitForChild(Player.Name) local music = Instance.new("Sound",Character) music.SoundId = "rbxassetid://993959716" music.Name = "AMusic" if db and Player.Team == Police then db = false music:Play() Light.Color = Color3.fromRGB(0,255,0) Door.Position = Vector3.new(-155.7, 105.225, -332.925) Window.Position = Vector3.new(-155.65, 106.626, -332.925) wait(4) Door.Position = Vector3.new(-156.6, 105.225, -327.925) Window.Position = Vector3.new(-156.6, 106.626, -327.925) Light.Color = Color3.fromRGB(255,0,0) db = true else warn("This Person is not a Police Team Person") end end end
Finally, the connect function:
Sensor.Touched:Connect(Everything)
The Error it gives is on line 26 and it is:
17:33:39.710 - Team is not a valid member of Model
Any Ideas on how to fix this?
Well where do I start? You define local PlayerV = game.Workspace:FindFirstChild("Head")
as "head" which won't work obviously unless you are searching for an actual part in the workspace called Head then that wont work to find a player
You defined local Player = part.Parent
this wont work because Part.Parent is the character, you cant find the players team from the character
Why did you define player like 3 times you already have the player once inside the function local plr = game.Players:GetPlayerFromCharacter(part.Parent)
Please dont put the parent arguments inside of the instance.new parameters, it's deprecated now!
And as @theking48989987 said above change your if statement pls
The problem appears to be that the Player variable is actually the character of the other player, which is a model and does not have a team property.
A quick fix would be to substitute of
if db and Player.Team == Police then
with
if db and plr.Team == Police then
as plr is defined as an actual player object
Hopefully this helped! be sure to accept if it did!