Simple Team Changing Script Not Working

  1. What do you want to achieve?
    I want to make a team changing script where the player touches a door and the script changes the player’s team.

  2. What is the issue?
    I’m not really sure what the issue is so I came here for some help :slight_smile:. However, I am getting an error in the output and I don’t know what it means.
    [Workspace.Door.TeamChangeScript:9: Expected identifier when parsing expression, got ‘)’]

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried doing script.Parent.Touched:Connect(function(OnTouch(hit))) but it doesn’t fix anything.

local function OnTouch(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.parent)
	if player then
		local Teams = game:GetService("Teams")
		hit.Team = Teams.BlueTeam

1 Like

you could try maybe like

if v.Parent:FindFirstChildOfClass('Humanoid') then
game.Players[v.Parent.Name].Team = game.Teams.BlueTeam
1 Like

Oh its because you did :Connect(function(onTouch))

If you are connecting to a already existant function then you do:


-- If it doesnt exist..



Thanks for the help, it worked!

That doesn’t seem to work for me either.

just a sidenote, if you plan to have fake npcs walking around in game you may want to add an additional check to verify that the model’s name is present in players to make sure it is a player and not the npc

1 Like