The purpose of this script is to change the team of the player to the Players team if they are part of the Winners team and teleport them back to spawn after touching the “BecomePlayerButton”. The script is located in ServerScriptService
local GameWorkspace = game:GetService("Workspace")
local MainSpawn = GameWorkspace.LobbyArea.SpawnLocation
local BecomePlayerButton = GameWorkspace.LobbyArea.WinnersHut.BecomePlayer
BecomePlayerButton.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local playername = hit.Parent.Name
local player = game.Players:FindFirstChild(playername)
local rootpart = hit.Parent:FindFirstChild("HumanoidRootPart")
print(player.Name)
if player.Team == game.Teams.Winners then
print("working")
player.Team = game.Teams.Players
rootpart.Position = Vector3.new(MainSpawn.Position.X, MainSpawn.Position.Y, MainSpawn.Position.Z)
end
end
end)
I believe the problem I am having with this script is that the game seems to still think the player is in the Players team after their team has already been swapped to the Winners team. The script is also unable to change the team of the player.
if player.Team == game.Teams.Players then
When using this if statement the script partially works and teleports the player even if the player is in the Winners team. I think this may be a problem with the script not checking the current value of the player’s team but I am unsure of how to do that. I would greatly appreciate if anyone knows why this is or if they could link a similar devforum post that solves this problem.