How do I make a script that plays a Sound ID on a player's head using a GUI TextButton so people nearby can hear them?

How do I make a script that plays a Sound ID on a player’s head using a GUI TextButton so people nearby can hear them? I am trying to make a chant GUI, but idk how to make a TextButton Script that plays a sound on someone’s head.

2 Likes

Use a LocalScript that sends data to the server using a RemoteEvent and have the server handle inserting the sound instance to the player’s head.

is there a way thats a bit more simple?

Thats the only way I know. You might be able to find one on Youtube thats easier.

i tried to look for one but i couldnt find it

Others wont hear it if you don’t use remotes.

Yeah, thats probably the only and easiest way. I don’t work a lot with sounds. That is the easiest and only way I would use and know.

are there any tutorials online?

Probably, most scripting is online. It might not be the exact thing you’re looking for but you might be able to put it together with more than one video. I found it easiest to just play around on a normal baseplate to figure it out. You can go along with the video.

What I would do is put the following script into the players backpack. Its very important that it is a server script, otherwise the other players will not hear it. I don’t think that’s recommended to do so, but you can give it a try!

-- This creates the sound inside the characters head

local SoundID = "rbxassetid://1838058421" -- Put your SoundID here

local PlayerHead = script.Parent.Parent.Character:FindFirstChild("Head")

local sound = Instance.new("Sound")

sound.Parent = PlayerHead

sound.SoundId = SoundID

-- This plays the sound if the player presses the button

local TextButton = script.Parent.Parent.PlayerGui:WaitForChild("ScreenGui").TextButton -- GUI Button

TextButton.MouseButton1Click:Connect(function()

sound:Play()

end)
2 Likes

When I reset it stops working. How do I fix this?

1 Like

You can set your ScreenGui to “ResetOnSpawn = false”. That solves the problem for some cases, but sometimes this bool needs to be set on true. Therefore I have revised the script again:

-- This creates the sound inside the characters head

local SoundID = "rbxassetid://1838058421" -- Put your SoundID here

local Players = game:GetService("Players")

local PlayerHead = script.Parent.Parent.Character:FindFirstChild("Head")

local player = Players:GetPlayerFromCharacter(script.Parent.Parent.Character) -- Gets the player from his character

local sound = Instance.new("Sound")

sound.Parent = PlayerHead

sound.SoundId = SoundID

-- This plays the sound if the player presses the button

local TextButton

function getPlayerButton()

wait(1)

TextButton = player.PlayerGui:FindFirstChild("ScreenGui").TextButton -- GUI Button

end

getPlayerButton() -- Fires function

function onCharacterAdded(character) -- Fires if the player respawns

getPlayerButton()

sound = PlayerHead.Sound

end

player.CharacterAdded:Connect(onCharacterAdded) -- Detects the respawn

TextButton.MouseButton1Click:Connect(function() -- Checks if the button was pressed

sound:Play()

end)
1 Like