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

How do I play music based on team?

Asked by 5 years ago

So I want to make it so that different music plays depending on different teams. Here is my script.

local EuropeanTheme = game.ServerStorage:WaitForChild("Fantasy Life- Theme of Fantasy Life")
local AmericanTheme = game.ServerStorage:WaitForChild("Fantasy Life - Theme of intrigue")

game.Players.PlayerAdded:Connect(function(Player)
    if Player.TeamColor == "Crimson" then
        AmericanTheme.Playing = true
    end
    if Player.TeamColor == "Bright blue" then
        EuropeanTheme.Playing = true
    end
end)
1
its supposed to be AmericanTheme:Play() and EuropeanTheme:Play() mixgingengerina10 223 — 5y
0
Compare the TeamColor to a BrickColor. DeceptiveCaster 3761 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I have no clue if this works, or not but here is what I edited/errors:

Music Playing Error:

-- on line 6 and 9:
AmericanTheme.Playing = true -- is incorrect
-- use this instead:
AmericanTheme:Play()
-- also make sure the audio properties is looped. (Looped = true)

Team Dectating Error:

if Player.TeamColor = "blah" then -- will not work
-- Use This Instead:
modelname = "bjh"

if game.Players:playerFromCharacter(Player).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then
-- It works better and allows a easy to edit team name.

Final Code:


modelname = "Blah" -- put the american team name here. modelnameB = "Blah2" -- put the european team name here. local EuropeanTheme = game.ServerStorage:WaitForChild("Fantasy Life- Theme of Fantasy Life") local AmericanTheme = game.ServerStorage:WaitForChild("Fantasy Life - Theme of intrigue") game.Players.PlayerAdded:Connect(function(Player) if game.Players:playerFromCharacter(Player).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then AmericanTheme:Play() end if game.Players:playerFromCharacter(Player).TeamColor==game.Teams:findFirstChild(modelnameB).TeamColor then EuropeanTheme:Play() end end)

Enjoy, and if this works please accept.

0
It doesn't work. Instead of it playing the music, I get an error on line 8 saying: attempt to index a nil value. TornadoCookie 20 — 5y
Ad
Log in to vote
0
Answered by 3 years ago

I have no idea if this works, but try it.

modelname = "SomethingTeam"
modelnameB = "OtherTeam"

local EuropeanTheme = game.ServerStorage:WaitForChild("Fantasy Life- Theme of Fantasy Life")
local AmericanTheme = game.ServerStorage:WaitForChild("Fantasy Life - Theme of intrigue")

game.Players.PlayerAdded:Connect(function(Player)
    wait(.1)
    if game.Players:FindFirstChild(Player.Name).TeamColor == BrickColor.new("the color") then
        AmericanTheme:Play()
    end
    if game.Players:FindFirstChild(Player.Name).TeamColor == BrickColor.new("the color") then
        EuropeanTheme:Play()
    end
end)

Answer this question