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

Im Trying To Make a Custom Chat And Trying To Use a RemoteFunction But It Keeps Giving Me An Error?

Hi There, So Basiclly I Want To Make A Custom Chat That Works And Everything Is In One Gui And So I Tried Using A RemoteFunction But I Keep Getting This Error bad argument #1 (string expected, got Object) (Line 6) Here Is The LocalScript:

local input = script.Parent:WaitForChild("ChatBox")

input.FocusLost:Connect(function(enterPressed)
	if enterPressed == true then
		if string.len(input.Text) > 0 then
			script.Parent.Parent.Parent.ReF:InvokeServer(input.Text)
			input.Text = ''
		end
	end
end)

And Here Is The Normal Script:

local send = game:GetService("MessagingService")
local chatted = 'ChatConnected'


script.Parent.Parent.Parent.ReF.OnServerInvoke = function(input)
	if input == string.len(input) > 0 then
		send:PublishAsync(chatted,'{'.. script.Parent.Parent.Parent.Parent.Parent.Name.. '} '.. input)
	end
end

And Just Incase Here Is The Chat Text Script And GetFocus Script I Have Made:

ChatText (Script)

local Get = game:GetService("MessagingService")
local chatted = 'ChatConnected'

Get:SubscribeAsync(chatted,function(msg)
	script.Parent.Chat8.Text = script.Parent.Chat7.Text
	script.Parent.Chat7.Text = script.Parent.Chat6.Text
	script.Parent.Chat6.Text = script.Parent.Chat5.Text
	script.Parent.Chat5.Text = script.Parent.Chat4.Text
	script.Parent.Chat4.Text = script.Parent.Chat3.Text
	script.Parent.Chat3.Text = script.Parent.Chat2.Text
	script.Parent.Chat2.Text = script.Parent.Chat1.Text
	script.Parent.Chat1.Text = msg.Data
end)

GetFocus (LocalScript)

local uis = game:GetService("UserInputService")
local chatBox = script.Parent:WaitForChild("ChatBox")

uis.InputBegan:Connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.Slash and not gameProcessed then
		chatBox:CaptureFocus()
		wait()
		chatBox.Text = ''
	end
end)

Please Help If You Can Since This Is My First Time Using A RemoteFunction. Thank You!

2 comments

0

Do you have a string value

0

yh

1 answer

Perhaps you have a child of input (ChatBox) called text? If so, try renaming it to something else. Also, add an extra parameter to script.Parent.Parent.Parent.ReF.OnServerInvoke = function(input) like this:

script.Parent.Parent.Parent.ReF.OnServerInvoke = function(player, input)

The parameter player is automatically added.

2 comments

0

nope i get a different error this time (attempt to compare number and boolean)(Line 6)

0

oh

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