I have been trying to get a system to detect player teams on the client so I can play music while the game is running or if you are waiting in the lobby. But I have tried doing it over and over again with no result. Can anyone give me a hand?
local script
local ReplicatedStorage = game.ReplicatedStorage local Music = script.Parent.Music local result = ReplicatedStorage.TeamCheck:InvokeServer() local id = {"Placeholder", "Placeholder", "Placeholder"} -- these are placeholders to prevent stealing print(result) while true do wait(0.5) if result == 1 then Music:play() Music.SoundId = "rbxassetid://"..id[1] else if result == 2 then Music.Playing = true Music.SoundId = "rbxassetid://"..id[2] else Music.Playing = true Music.SoundId = "rbxassetid://"..id[3] end end end
server script
game.ReplicatedStorage.TeamCheck.OnServerInvoke = function(player) if player.TeamColor == BrickColor("Pearl") then print("1") return 1 else if player.TeamColor == BrickColor("Really red") then print("2") return 2 end end end
local Teams = game:GetService("Teams") local TargetTeam = Teams:FindFirstChild("Team") if Player.Team == TargetTeam then --Do stuff end
Edit: Try changing your server script to this:
local team1 = "TeamName1" local team2 = "TeamName2" game.ReplicatedStorage.TeamCheck.OnServerInvoke = function(player) if player.Team == team1 then print("1") return 1 else if player.Team == team2 then print("2") return 2 end end end
Change Team Name 1 and Team Name 2 to your team names and never use brickcolor to check anything.