Why won't this player team teleporter work?

Hi, I am trying to make a script that teleports players on a specific team to a specific part.
The problem is it won’t do that, and there are no errors so I can’t tell why it’s not working, I do think it has something to do with player.team though.

local Map = script.Parent
local Players = game.Players:GetPlayers()
local StartMap = game.ServerScriptService.Script.StartMap

function teleportPlayers(player)
	if player.Team == "Lithuania" then
		player.Character.HumanoidRootPart.CFrame = Map.LithuanianSpawn.CFrame
	end
	if player.Team == "Russia" then
		player.Character.HumanoidRootPart.CFrame = Map.RussiaSpawn.CFrame
	end
end

StartMap.Event:Connect(teleportPlayers)
1 Like

That’s not an actual event. ahhh 30 chers

1 Like

it is an event from another script

1 Like

I think I might be wrong but the player.Team value type is an object type, which means you’ll have to localize the teams

local Map = script.Parent
local Players = game.Players:GetPlayers()
local StartMap = game.ServerScriptService.Script.StartMap
local Teams = game.Teams

function teleportPlayers(player)
	if player.Team == Teams.Lithuania then
		player.Character.HumanoidRootPart.CFrame = Map.LithuanianSpawn.CFrame
	end
	if player.Team == Teams.Russia then
		player.Character.HumanoidRootPart.CFrame = Map.RussiaSpawn.CFrame
	end
end

StartMap.Event:Connect(teleportPlayers)
2 Likes

Obviously, something’s not right.

First of all, you have to add a value to the teleportPlayers function, which you haven’t done in the StartMap.Event:Connect(teleportPlayers) line.

Considering you’re using a connect argument with a custom function, I’m not sure if you can add a value for the function which leaves it completely useless.

2 Likes

wdym by add a value to teleportPlayers

1 Like

Why don’t you use SpawnLocation’s?

2 Likes

If you don’t want that, you should use player.TeamColor instead of player.Team.

1 Like

I can try and use team spawn locations actually

1 Like

Let me know if it works. --30–

1 Like

Right now I’m trying to find a way to kill all the players so they spawn, but it won’t work

local Map = script.Parent
local Players = game.Players:GetPlayers()
local StartMap = game.ServerScriptService.Script.StartMap
local Teams = game.Teams

function teleportPlayers()
	for i,v in pairs(game.Players:GetChildren()) do
		v.Character.Head:Destroy()
	end
end

StartMap.Event:Connect(teleportPlayers)

I assume StartMap is a remote Event? In that case, your function is missing the OnClientEvent

Player:LoadCharacter can be used to respawn a player.

As OP has stated in post #3, it is an event from another script, which means it is a BindableEvent.