Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I detect teams locally?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
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.

0
ok this just makes me lost. Icelogist 11 — 3y
0
Lost? Explain. Bankrovers 226 — 3y
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. Icelogist 11 — 3y
0
update: I see that you updated your answer I will look at it and I will approve it. if it works. Icelogist 11 — 3y
View all comments (5 more)
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. Bankrovers 226 — 3y
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"). Bankrovers 226 — 3y
0
(The comments may be a bit mixed up I think the site is a bit slow) Bankrovers 226 — 3y
0
true Icelogist 11 — 3y
0
Welp, It didn't work Icelogist 11 — 3y
Ad

Answer this question