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

How do I play sounds for specific players?

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

1 comment

0

Parent the sound to the player?

1 answer

✓ Accepted answer

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

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