Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how can i play audio based on the players team?

hi, i have 2 teams in my game already (Lobby and Playing) and 2 sounds which are numbered Sound1 and Sound2. i need Sound1 to play to players who are in the Lobby team and Sound 2 to play to players in the Playing team.

this is a script i thought could be a start:

game.Players.LocalPlayer.Team = "Lobby" 
	Sound1:Play()
	Sound2:Stop()
end

thanks in advance from poopypigeon245

1 answer

ok i think you wanted to play a sound when player joins a team if it is then use this code


--1 Step Create A server script(normal script)
--2 Step create a local script in replicated first
-- replace REMOTEEVENTLOCATION with location you putted your remote event
--replace soundlocation with the sound you want to use location
--Server Script(normal script)
function ForLobby(plr)
	REMOTEEVENTLOCATION:FireClient(plr,plr,"Lobby")
end
function ForPlaying(plr)
	REMOTEEVENTLOCATION:FireClient(plr,plr,"Playing")
end
game.Teams.Playing.PlayerAdded:connect(ForPlaying)
game.Teams.Lobby.PlayerAdded:connect(ForPlaying)
--Local Script in replicated first
function OnInvoke(plr,team)
	if team == "Lobby" then
		SOUNDLOCATION:Play()
	elseif team == "Playing" then
		SOUNDLOCATION:Play()
	end
end
REMOTEEVENTLOCATION.OnClientEvent:connect(OnInvoke)

Hope i helped :)

2 comments

0

i put Playing and Lobby in "marks because they were underlined in blue. i changed sound1location and sound2location to game.Workspace.Sound1/Sound2. i put a remotefunction in ServerStorage and changed REMOTEEVENTLOCATION to game.ServerStorage.RemoteEvent but it still didnt work (both the script and the localscript are in workspace)

0

ok i edited this script ,don't forget to put localscript in replicated storage and if you get any errors be sure to tell me

This discussion is preserved as it was. New answers, comments, and votes are closed.