Team only script

Ok so here is the problem I made a script (input detector) for it to only work for a specific team and it worked but when the team was changed to another team the script would still work for them I need the script to stop working when the player goes to another team have any ideas? Any help is appreciated thanks! and here is the code (btw Jay is the name of the team) unless u rejoin the game in another team only then the script wouldnt work for you

game.Players.PlayerAdded:Connect(function(player)
wait(2)
if player.Team == game.Teams.Jay then
print("is on jay team")

  player.Character.InputDetector.Disabled = false
end
end)
3 Likes

You used the playeradded event, so it wont work multiple times

2 Likes

Try using CharacterAdded which will print it each time the player spawns or respawns (including a team change on death.)

1 Like

Ok I will try try that and will tell the results

2 Likes

Did you try it and receive any results yet?

1 Like

I tried and failed and im almost sure I did it wrongly no offense can u edit the script and send it?

1 Like
game.Players.PlayerAdded:Connect(function(player)
wait(2)
 player:GetPropertyChangedSignal("Team"):connect(function()
  if player.Team == game.Teams.Jay then
  print("is on jay team")
    player.Character.InputDetector.Disabled = false
 end)
end
end)

This should work

I tried that now the script doesnt work at all it didnt work for either team probably because there is a small mistake in the script the output read
ServerScriptService.lightning only:7: Expected identifier when parsing expression, got ‘)’ - Studio - lightning only:7

game.Players.PlayerAdded:Connect(function(player)
wait(2)
 player:GetPropertyChangedSignal("Team"):connect(function()
  if player.Team == game.Teams.Jay then
  print("is on jay team")
    player.Character.InputDetector.Disabled = false
 end
end)
end)

Try this very so slightly modified version of xXxIAsdasIxXx’s script

Ok so here are the results its confusing
the initial problem was that when teams were swiched the script will still work for both teams but with the edited script its the exact same thing but when u spawn on the Jay team the script didnt work until u switched sides to the Kai team then back to jay so no it didnt work :frowning: im startin to lose hope is there any way to make team only scripts?

The Connect() should be capitalized

1 Like

I think you forgot this “else” :

game.Players.PlayerAdded:Connect(function(player)
	wait(2)
	player:GetPropertyChangedSignal("Team"):Connect(function()
		if player.Team == game.Teams.Jay then
			print("is on jay team")
			player.Character.InputDetector.Disabled = false
		else
			player.Character.InputDetector.Disabled = true
		end
	end)
end)

HOLY COW I THINK YOUR SCRIPT WORKED! Even I forgot else im such a noob after further testing I will mark you as solution is all goes well thanks so much! :smiley:

I have a problem the script works but when we reset character on the same team it doesnt work we have to go and change the team again ie going to team kai then back to jay for the script to work any fix for that?

Scripts in some places, like starterPlayerScripts, will only run when the player first joins the game.

so you want to it to also work if the player reset their character.
well, perhap by using ChildAdded Event you do so.

Perhap :upside_down_face: :

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(character)
	if player.Team == game.Teams.Jay then
		local inputDetector = character:FindFirstChild("InputDetector")
			if inputDetector then
				inputDetector.Disabled = false
			end
		end
	end
	player:GetPropertyChangedSignal("Team"):Connect(function()
		if player.Team == game.Teams.Jay then
			print("is on jay team")
			player.Character.InputDetector.Disabled = false
		else
			player.Character.InputDetector.Disabled = true
		end
	end) 
end)


reply to wrong person. sorry
########

complete failure the initial script itself stopped working but its a small fix here is the output
ServerScriptService.lightning only:10: Expected ‘)’ (to close ‘(’ at line 1), got ‘player’
probably a small error can u fix it please?

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(character) wait()
		if player.Team == game.Teams.Jay then
			local inputDetector = character:FindFirstChild("InputDetector")
				if inputDetector then
					inputDetector.Disabled = false
				end
			end
		end
	end)
	player:GetPropertyChangedSignal("Team"):Connect(function()
		if player.Team == game.Teams.Jay then
			print("is on jay team")
			player.Character.InputDetector.Disabled = false
		else
			player.Character.InputDetector.Disabled = true
		end
	end) 
end)