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

How do I detect teams locally?

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

1 answer

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.

9 comments

0

ok this just makes me lost.

0

Lost? Explain.

0

all you did was give me 4 lines of code without saying anything I would at lease like one peace of advice to tell me what I did wrong like "you miss spelled a word on line 11" or tell me what to add or remove. But just giving me code with no context is not gonna help. Even just saying things about it without giving me code can help too. Sorry if I appear rude just want to let you know.

0

update: I see that you updated your answer I will look at it and I will approve it. if it works.

0

You're right, but see if my edit works. Player.Team is an Object not a string as everyone expects. You also keep your script much clearer if you don't use brickcolor but strings.

0

For example, you also did Brickcolor("Pearl") with your local script on line 6. This doesn't work, it should be BrickColor.new("Pearl").

0

(The comments may be a bit mixed up I think the site is a bit slow)

0

true

0

Welp, It didn't work

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