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

Custom chat function not working?

Hi, I'm currently testing a prototype for a custom chat using a text box, scripts and a text label. It doesn't display a error, but when I press enter, the script doesn't work and the text doesn't appear. I am currently on my MacBook, so I can't show any gifs but here's the scripts.

LocalScript:

local userInput = game:GetService("UserInputService")

userInput.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Return then
		if script.Parent.TextBox.Text == "" then
		else
			local text = script.Parent.TextBox.Text
			game.ReplicatedStorage.chatFunction:FireServer(text)
			script.Parent.TextBox.Text = ""
		end
	end
end)

Script:

local function Chat(text)
	local CloneText = script.Parent.TextLabel:Clone()
	CloneText.Visible = true
	CloneText.Text = text
	if CloneText ~= nil then
		if CloneText.Position == UDim2.new(0.1, 0, 0.65, 0) then
			CloneText.Position = CloneText.Position - UDim2.new(0, 0, 1, 0)
		else
			CloneText.Position = UDim2.new(0.1, 0, 0.65, 0)
		end 
	end
end

game.ReplicatedStorage.chatFunction.OnServerEvent(Chat)

1 answer

✓ Accepted answer

sry for bad english

Try this out : (Maybe you need to edit it)

--Server Script:

 game.ReplicatedStorage.chatFunction.OnServerEvent:Connect(function(plr,text)
 	local CloneText = script.Parent.TextLabel:Clone()
     CloneText.Visible = true
     CloneText.Text = text
     if CloneText ~= nil then
         if CloneText.Position == UDim2.new(0.1, 0, 0.65, 0) then
            CloneText.Position = CloneText.Position - UDim2.new(0, 0, 1, 0)
         else
             CloneText.Position = UDim2.new(0.1, 0, 0.65, 0)
         end 
     end
 end)

the functions connected to OnServerEvent will be passed the player who fired the event as the first parameter.

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

4 comments

0

This just caused more errors. 11:58:58.503 - Players.Ha_rriz.PlayerGui.ScreenGui.Script:4: bad argument #3 to 'Text' (string expected, got Object)

0

wait let me edit it

0

what happens when you add this after line 1 : print(text)

0

That will literally just print the text in the output. It won't do anything to the chatting function. And I already fixed it so.

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