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

How do I play sounds for specific players?

Asked by
P100D 590 Moderation Voter
9 years ago

For example, those that are on a specific team, without the other team hearing.

0
Parent the sound to the player? NotsoPenguin 705 — 9y

1 answer

Log in to vote
0
Answered by
Scriptree 125
9 years ago

So here is a script that adds a sound to the player if he's on a specific team, i explained everything in the script as much as I can.

wait() -- just to make sure a player has spawned
for _, plr in pairs(game.Players:GetPlayers()) do -- iterating through all players
    if plr.TeamColor == BrickColor.new("Bright red") then -- checking if player's teamcolor is the color "Bright red" 
        local plrgui = plr:findFirstChild("PlayerGui") --getting PlayerGui
        if plr and plrgui then -- checking if player and playergui exist to prevent any bugs (Not necessary)
            local sound = Instance.new("Sound", plrgui) -- Creating the sound and parenting it to the playergui so it plays it locally
            sound.SoundId = "rbxasset://sounds/HalloweenGhost.wav" -- insert the id of the song u want
            sound:Play() -- play the song, change it to "sound:Stop()" to stop the song
        end
    end
end

Hope it helped! :D

Ad

Answer this question