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

How can you make it so when a player chats, a sound plays?

Hi there. I've been struggling with this for a while now since I'm not a programmer or anything like that, I just know basic things around scripting.

I'm trying to make a walkie-talkie tool that essentially works like this:

  • the player chats while the tool is equipped
  • a sound in the tool plays for the server, not just for the local player
  • if the tool is unequipped, this won't happen

Tool looks like this

The playerChats script looks like this:

local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local tool = script.Parent.Parent

tool.Equipped:Connect(function()
	Player.Chatted:Connect(function()
		script.Parent.Chatted:FireServer()
	end)
end)

The playSound script looks like this:

script.Parent.Chatted.OnServerEvent:Connect(function()
	script.Parent.Sound:Play()
end)

Thank you for your help <3

2 comments

0

NOTE: There is nothing in the output that shows me anything I'm doing wrong, it just doesn't play. I've tried all different kinds of sounds / volumes, no dice.

0

Did you parent the sound to the tool and not the handle? I've had problems with it too, though.

1 answer

A local script probably isn't needed. I'm assuming that you want it to a play a sound across the whole server, in which case you can do this:

This should be a server script.

local Players = game:GetService("Players")
local tool = script.Parent.Parent

tool.Equipped:Connect(function()
    local player = Players:FindFirstChild(script:FindFirstAncestorOfClass("Model").Name)
    player.Chatted:Connect(function()
	script.Parent.Sound:Play()
    end)
end)

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