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

Chat script cannont concantenate local 'msg'?

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)

3 comments

0

There's no end in the third or first code; is this not the full script, if not, could you please provide it? :) And are you using a Local or Server script?

0

This legit is on a video. From a year ago too.

0

First of all, you have -5 points. You cannot criticize me. This was a year ago. There is no ******* need to reply.

1 answer

✓ Accepted answer

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")

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