Trouble with detecting player teams on a gui localscript

Hi, I’m trying to get players to have ambience/music in the background playing based on which team they’re on without the audio itself resetting. For some reason despite every other piece of code properly working, the moment I put in a line to detect which team the player is on the script broke without giving an error.

Line in question:

if player.Team == "Undecided" then

Directories for reference:
image
image

if player.Team == "Undecided" then
-- attempt to compare Instance with string, resulting in false

correct way should be to check Instance and Instance:

if player.Team == Teams.Undecided then
2 Likes

You used if player.Team == "Undecided" then, try using if team == game.Teams.Undecided then.

Here is an example of how you could use this:

local UndecidedAmbience = game.Workspace.SoundFx.UndecidedAmbience
local Team1Ambience = game.Workspace.SoundFx.Team1Ambience
local Team2Ambience = game.Workspace.SoundFx.Team2Ambience

local player = game.Players.LocalPlayer
local team = player.Team

if team == game.Teams.Undecided then
	UndecidedAmbience:Play()
elseif team == game.Teams.Team1 then
	Team1Ambience:Play()
elseif team == game.Teams.Team2 then
	Team2Ambience:Play()
end

Also, make sure everything is spelt right.

Here are pictures of what my explorer looks like:
image
image
image

Note: if you don’t have a “undecided” team, but want players to hear the UndecidedAmbience if they have not selected a team yet, just change the following:

if team == game.Teams.Undecided then
	UndecidedAmbience:Play()
elseif team == game.Teams.Team1 then
	Team1Ambience:Play()
elseif team == game.Teams.Team2 then
	Team2Ambience:Play()
end

to

if team == game.Teams.Team1 then
	Team1Ambience:Play()
elseif team == game.Teams.Team2 then
	Team2Ambience:Play()
else
	UndecidedAmbience:Play()
end

please reply if it does not work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.