Basically whenever a Player respawns and they are on one of the following teams they are supposed to get a sound object added to their PrimaryPart.
Even though I am certain that I am on the correct team, the print message does not appear in the console (“Team is correct!”), which indicates that the script is not working.
I have no idea what the cause for this could be. Keep in mind this is a regular script.
game.Players.PlayerAdded:Connect(function(Player)
print("Player Added")
Player.CharacterAdded:Connect(function(Character)
print("Character Added")
local team = Player.Team
if team ~= nil then
if team.Name == "Autobahnpolizei" or team.Name == "Feuerwehr" or team.Name == "Polizei" or team.Name == "Rettungsdienst" or team.Name == "SEK" or team.Name == "THW" or team.Name == "Zoll" then
print("Team is correct")
Player.PlayerGui.FunkGui.Enabled = true
local sound = Instance.new("Sound")
sound.Volume = 0.1
sound.RollOffMaxDistance = 10
sound.RollOffMinDistance = 1
sound.Parent = Character
end
end
end)
end)
Well as I have explained the if team.Name == "Autobahnpolizei" or team.Name == "Feuerwehr" or team.Name == "Polizei" or team.Name == "Rettungsdienst" or team.Name == "SEK" or team.Name == "THW" or team.Name == "Zoll" then line is essential to determine, which team gets the sound added into their character.
local Teams = { --Make a table of all the teams you can be on (Replace with your team names)
"Team1",
"Team2",
"Team3",
}
game.Players.PlayerAdded:Connect(function(Player)
print("Player Added")
Player.CharacterAdded:Connect(function(Character)
print("Character Added")
local team = Player.Team
if team ~= nil then
if Teams[team.name] then--Check if player is on any of the teams in the list
print("Team is correct")
Player.PlayerGui.FunkGui.Enabled = true
local sound = Instance.new("Sound")
sound.Volume = 0.1
sound.RollOffMaxDistance = 10
sound.RollOffMinDistance = 1
sound.Parent = Character
end
end
end)
end)
Make sure that the player gets assigned a team before this runs
My recommendation would be to take a different approach:
for i, v in pairs(game:GetService('Teams'):GetChildren()) do
v.PlayerAdded:Connect(function(Player)
local team = v
print(team)
if team.Name == "Autobahnpolizei" or team.Name == "Feuerwehr" or team.Name == "Polizei" or team.Name == "Rettungsdienst" or team.Name == "SEK" or team.Name == "THW" or team.Name == "Zoll" then
print("Team is correct")
Player.PlayerGui.FunkGui.Enabled = true
local sound = Instance.new("Sound")
sound.Volume = 0.1
sound.RollOffMaxDistance = 10
sound.RollOffMinDistance = 1
sound.Parent = Player.Character
end
end)
end
This way, you can also get the player when they change teams as well
– Also one more thing, it’s best to edit the playerGui stuff in local scripts, I would recommend sending a remote event to the client for that