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

Why isn't the chat saying anything when programmed?

My game requires text to go through the chat informing the players what triggered the alarm. It isn't working. Here's the code I tried:

script.Parent.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if (h) then
		local items = game.ReplicatedStorage.PlayerAssets[hit.Parent.Name].Inventory:GetChildren()
		if #items ~= 0 then
			game.Workspace.GameScriptService.StatusScript.GameStatus.Value = "Loud"
			game.Chat:Chat(hit.Parent.Name.." set off the Metal Detectors!", Color3.fromRGB(0, 0, 0))
		end
	end
end)

What's wrong with it? Bit of help please! Thanks so much!

3 comments

0

Are you trying to get a bubble over someone/something's head, or are you trying to get a message in the actual chat GUI?

0

In the actual Chat Gui

1 answer

Since the chat exists locally, you need to use remote events or functions to have something display on everyone's chat. So to do this, you place a remote event in ReplicatedStorage named "SendMessage", and then in startergui, you place a local script handling the messages being sent from the server, and in your existing server script, you have a function handling the message to be sent.

Local script placed inside StarterGui:

local SendMessage = game.ReplicatedStorage.SendMessage
SendMessage.OnClientEvent:Connect(function(chatProperties) --Recieves the event sent from the player (excluding the player argument if we used :FireClient()
	game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",chatProperties) --Outputs the message to the client’s chat window
end)

Your server script:

local SendMessage = game.ReplicatedStorage.SendMessage -- a remote event

local function say(msg)
	SendMessage:FireAllClients({  --FireAllClients will send it to every player in the players server, you can also use SendMessage:FireClient(player Target, chatProperties)
		Text = msg; --The message to be printed (Required)
		Color = Color3.fromRGB(0,255,215); --The colour of the output text (Optional, will default to a white-ish colour)
		Font = Enum.Font.SourceSans; --The font of the message (Optional, will default to SourceSans)
		FontSize = Enum.FontSize.Size18; --The size of the message (Optional, will defualt to Size18)
	})
end

script.Parent.Touched:Connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if (h) then
        local items = game.ReplicatedStorage.PlayerAssets[hit.Parent.Name].Inventory:GetChildren()
        if #items ~= 0 then
            game.ServerScriptService.StatusScript.GameStatus.Value = "Loud" --server script service is not in the workspace
            say(hit.Parent.Name.." set off the Metal Detectors!", Color3.fromRGB(0, 0, 0))
        end
    end
end)

If this answers your question, then mark it as the accepted answer.

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