Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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:

01local input = script.Parent:WaitForChild("ChatBox")
02 
03input.FocusLost:Connect(function(enterPressed)
04    if enterPressed == true then
05        if string.len(input.Text) > 0 then
06            script.Parent.Parent.Parent.ReF:InvokeServer(input.Text)
07            input.Text = ''
08        end
09    end
10end)

And Here Is The Normal Script:

1local send = game:GetService("MessagingService")
2local chatted = 'ChatConnected'
3 
4 
5script.Parent.Parent.Parent.ReF.OnServerInvoke = function(input)
6    if input == string.len(input) > 0 then
7        send:PublishAsync(chatted,'{'.. script.Parent.Parent.Parent.Parent.Parent.Name.. '} '.. input)
8    end
9end

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

ChatText (Script)

01local Get = game:GetService("MessagingService")
02local chatted = 'ChatConnected'
03 
04Get:SubscribeAsync(chatted,function(msg)
05    script.Parent.Chat8.Text = script.Parent.Chat7.Text
06    script.Parent.Chat7.Text = script.Parent.Chat6.Text
07    script.Parent.Chat6.Text = script.Parent.Chat5.Text
08    script.Parent.Chat5.Text = script.Parent.Chat4.Text
09    script.Parent.Chat4.Text = script.Parent.Chat3.Text
10    script.Parent.Chat3.Text = script.Parent.Chat2.Text
11    script.Parent.Chat2.Text = script.Parent.Chat1.Text
12    script.Parent.Chat1.Text = msg.Data
13end)

GetFocus (LocalScript)

01local uis = game:GetService("UserInputService")
02local chatBox = script.Parent:WaitForChild("ChatBox")
03 
04uis.InputBegan:Connect(function(key, gameProcessed)
05    if key.KeyCode == Enum.KeyCode.Slash and not gameProcessed then
06        chatBox:CaptureFocus()
07        wait()
08        chatBox.Text = ''
09    end
10end)

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

0
Do you have a string value JesseSong 3916 — 5y
0
yh mahid786 41 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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:

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

The parameter player is automatically added.

0
nope i get a different error this time (attempt to compare number and boolean)(Line 6) mahid786 41 — 5y
0
oh youtubemasterWOW 2741 — 5y
Ad

Answer this question