Basically, I made a chat. On the main script, an error occurs on line 20, "attempt to concantenate local 'msg' a nil value" I have no idea whats wrong with it. Nor do I know what this means...
ServerScript:
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 == 12 then v:Destroy() else v.Name = "line" .. tostring(tonumber(LineNumber) + 1) v.Position = v.Position - UDim2.new(0, 0, 0.035, 0) end end end end function NewLine(parent, plr, msg) local New = Instance.new("TextLabel", parent) New.Text = plr.Name .. ": " .. msg New.Size = UDim2.new(0.35, 0, 0.026, 0) New.Position = UDim2.new(0, 0, 0.315, 0) New.BorderSizePixel = 0 New.BackgroundTransparency = 1 New.TextColor3 = Color3.fromRGB(255, 255, 255) New.TextStrokeTransparency = 1 New.FontSize = "Size10" New.TextXAlignment = "Left" New.TextYAlignment = "Top" New.Name = "Line1" New.ClipsDescendants = true end workspace.Events.Other.Chat.OnServerEvent:connect(function(plr, msg) for _,v in ipairs(game:GetService("Players"):GetChildren()) do NewLine(v:WaitForChild("PlayerGui").Chat.Container.ChatLines, plr, msg) UpdateOldLabels(v:WaitForChild("PlayerGui").Chat.Container.ChatLines) end end)
LocalScript:
script.Parent.InputEnded:connect(function() game.Workspace.Events.Other.Chat:FireServer(game.Players.LocalPlayer, script.Parent.Text) script.Parent.Text = [[Click here or press the "/" key to chat.]] end)
The problem is that OnServerEvent automatically provides the player who's client fired the event, so you don't need to provide it.
Signal OnServerEvent (
??? Player player,
??? Variant... arguments
)
When you given the arguments player, message
to FireServer, the function connected to OnServerEvent receives the arguments player, player, message
. To fix this, try passing the text in as the only argument to FireServer.
Example:
Server
RemoteEvent.OnServerInvoke:Connect(function(player, message) print(player.Name .. " says: " .. message) end)
Client
RemoteEvent:FireServer("Message")