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

Chat Script Not Working At All?

In A ServerScript:

local CE = game.ReplicatedFirst.ChatEvent

function UpdateOldLabels(Parent)
    for i,v in pairs(Parent:GetChildren()) do
        if v.Name:sub(1,4):lower() == "line" then
            local LineNumber = v.Name:sub(5)
            if LineNumber == "6" then
                v:Destroy()
            else
                v.Name = "line"..tostring(tonumber(LineNumber) + 1)
                v.Position = v.Position - UDim2.new(0,0,0,30)
            end
        end
    end
end

function SC(instance, player, message, color,)
	UpdateOldLabels(instance)
	local TL = Instance.new("TextLabel")
	TL.Parent = instance
	TL.BackgroundTransparency = 1
	TL.Font = Enum.Font.SourceSansBold
	TL.FontSize = Enum.FontSize.Size18
	TL.Text = "["..player.Name.."]: "..message
	TL.TextColor = color
	TL.TextXAlignment = Enum.TextXAlignment.Left
	TL.TextYAlignment = Enum.TextYAlignment.Top
	TL.TextStrokeTransparency = 0.7
	TL.ClipsDescendants = false
	TL.Size = UDim2.new(1,0,0,30)
    TL.Position = UDim2.new(0,0,1,-30)
    TL.Name = "line1"
end

CE.OnServerEvent:connect(function(player, message, color)
	for i,v in pairs(game.Players:GetChildren()) do	
		local PG = v:WaitForChild("PlayerGui")	
		local CG = PG:WaitForChild("Chat")	
		SC(CG.GlobalChat, player, message, color)
	end
end)

In a LocalScript:

local P = game.Players.LocalPlayer
local TB = script.Parent.TextBox
local UIS = game:GetService("UserInputService")
local CE = game.ReplicatedFirst.ChatEvent
local CC = P.TeamColor

UIS.InputBegan:connect(function(input)
 if input.UserInputType == Enum.UserInputType.Keyboard and input.UserInputState == Enum.UserInputState.Begin and input.KeyCode == Enum.KeyCode.Slash then
	TB:CaptureFocus()
end
end)

TB.FocusLost:connect(function(enterpress)
	if enterpress then
		CE:FireServer(TB.Text, CC)
		wait(0.03)
		TB.Text = "Click here or press the '/' key to chat."
	else
		TB.Text = "Click here or press the '/' key to chat."		
	end
end)

It works in studio, but when I go into a game, the messages don't send through.

2 comments

0

Any output?

0

Check to see that the script is parented to an object that isn't specific to studio.

1 answer

✓ Accepted answer

Making a chat system can be very complicated sometimes, especially when first starting. I suggest watching this video I made covering the basics of creating a chat system here: https://www.youtube.com/watch?v=uoUfrm9ZUbI

It's basically just a small walkthrough and introduction to creating a stable network for a chat system. It also comes with an example you can work from, but if you have any questions, let me know.

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