Help with a Teams if statement

hey everyone i have problem with this animation team script i cant make it so if one player is in team 1 to do animation team 1 it says this

here is the code

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players.PlayerAdded
local Teams = game:GetService("Teams")
--get player
local idleShadowAnim = script:WaitForChild("IdleShadow")
local ShadowWalkAnim = script:WaitForChild("ShadowWalk")
local walkAnim = script:WaitForChild("Walk")
local ShadowWalkAnimTrack = humanoid.Animator:LoadAnimation(ShadowWalkAnim)
local idleSAAnimTrack = humanoid.Animator:LoadAnimation(idleShadowAnim)
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)

--get anims
local survivorbol = Instance.new("BoolValue")
survivorbol.Parent = script
survivorbol.Value = false
local shadowbol = Instance.new("BoolValue")
shadowbol.Parent = script
shadowbol.Value = false
--;
player:Connect(function(player)
	if player.Team == Teams.Shadow then
		shadowbol.Value = true
	else
		survivorbol.Value = true
	end
end)

if player.Teams == Teams.Shadow then
	shadowbol.Value = true
else
	survivorbol.Value = true
end
humanoid.Running:Connect(function(speed)
	
	if speed > 0 then
		if shadowbol.Value == true then
			ShadowWalkAnimTrack:Play()
			idleSAAnimTrack:Stop()
		elseif survivorbol.Value == true then
			walkAnimTrack:Play()
			idleShadowAnim:Play()
		else
			print("notvalue")
			
		end
	else
		if shadowbol.Value == true then
			idleSAAnimTrack:Play()
			ShadowWalkAnimTrack:Stop()
		elseif survivorbol.Value == true then
			print("didntstop?")
			else
		end
		
		end
	end)
		
--

You’re using Players.PlayerAdded, which is a signal. Try using Players.LocalPlayer instead, the LocalPlayer is always loaded when LocalScripts run.

The .PlayerAdded event doesn’t fire in local scripts (for the local player). You can try to work-around this by doing the following.

game.Players.ChildAdded:Connect(function(player)
	if player:IsA("Player") then
		--Player instance added to player's service.
	end
end)

PlayerAdded does fire in localscripts, actually

Also, shouldn’t you just use PlayerAdded since it’s always a player rather than ChildAdded?

It’ll fire for other players but not for yourself, is what I was referring to.

If you need a proxy .PlayerAdded event which will fire for the local player then you can listen for the event to fire in a server script and subsequently call :FireClient() or :FireAllClients() on a RemoteEvent instance.

If the original post’s script is a server script inside the StarterCharacterScripts folder then it’d be simpler to get the local player instance by doing one of the following.

local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
print(player.Name)
local character = script.Parent
local player = game.Players.GetPlayerFromCharacter(game.Players, character)
print(player.Name)

hey thanks for youre time i just fixed it thanks to (solution) it was a simple mistake that you also mention again thanks