Soundboard system

Hey,
i’m trying to make a soundboard system to make the game a bit more fun. So I made a script with the following content :

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg) --event that activating when player send message 
		if msg == "/halt" and player.Team == Teams.NTF then 
			local Sound = Instance.new("Sound")
			Sound.Parent = player.PlayerGui
			Sound.Name = "TestSound"
			Sound.SoundId = "rbxassetid://4657749134" -- Put here your soundid
			Sound.RollOffMode = Enum.RollOffMode.Linear
			Sound.MaxDistance = 10
			Sound:Play()
			Sound.Ended:Wait()
			Sound:Destroy()
		elseif msg == "/fbi" then
			local Sound = Instance.new("Sound")
			Sound.Parent = player.PlayerGui
			Sound.Name = "TestSound"
			Sound.SoundId = "rbxassetid://4964334807" -- Put here your soundid
			Sound.RollOffMode = Enum.RollOffMode.Linear
			Sound.MaxDistance = 10
			Sound:Play()
			Sound.Ended:Wait()
			Sound:Destroy()
		elseif msg == "/wow" then
			local Sound = Instance.new("Sound")
			Sound.Parent = player.PlayerGui
			Sound.Name = "TestSound"
			Sound.SoundId = "rbxassetid://1460707372" -- Put here your soundid
			Sound.RollOffMode = Enum.RollOffMode.Linear
			Sound.MaxDistance = 10
			Sound:Play()
			Sound.Ended:Wait()
			Sound:Destroy()
		elseif msg == "/alert" then
			local Sound = Instance.new("Sound")
			Sound.Parent = player.PlayerGui
			Sound.Name = "TestSound"
			Sound.SoundId = "rbxassetid://1011639456" -- Put here your soundid
			Sound.RollOffMode = Enum.RollOffMode.Linear
			Sound.MaxDistance = 10
			Sound:Play()
			Sound.Ended:Wait()
			Sound:Destroy()
		elseif msg == "/nice" then
			local Sound = Instance.new("Sound")
			Sound.Parent = player.PlayerGui
			Sound.Name = "TestSound"
			Sound.SoundId = "rbxassetid://2846571251" -- Put here your soundid
			Sound.RollOffMode = Enum.RollOffMode.Linear
			Sound.MaxDistance = 10
			Sound:Play()
			Sound.Ended:Wait()
			Sound:Destroy()
		end
	end)
end)

Problem is that it plays the sound for only one person (client side). I want to it play for everyone.

Instead of parenting the Sound to the PlayerGui, which is local for each client, you can parent it to the player’s Character, such as inside of its HumanoidRootPart.

It’ll then be audible to other players that are within range of the sound’s MaxDistance property from that player’s Character (because the sound will be emitting from that part in the Workspace instead of acting as a “global sound”).

Also, take note that the MaxDistance property is now deprecated in favor of RollOffMinDistance and RollOffMaxDistance.

1 Like

Hey there! :wave:

Try creating a Script in ServerScriptService and pasting the code in to it. Ensure you delete the current script! Once done, test it and let me know how it goes! :grinning_face_with_smiling_eyes:

Best of luck with resolving this issue! :heart:

Hey !
The script is alreayd in serverr script service (I’m dumb, but not at this point)

1 Like

As in @StrongBigeMan9 mentioned, parent the sound to the HumanoidRootPart of the character rather than the PlayerGui as that is local. Also I recommend fixing up the code a little bit since there’s a lot of repetition going on, which will prove to make adding more sounds a bit difficult with all the code repetition, especially if you have to change something such as the MaxDistance, which again, is now deprecated

You can get the HumanoidRootPart by player.Character.HumanoidRootPart, keep in mind that you’ll have to make a check that sees if the player’s Character exists firstly or else it will error

2 Likes