Invalid argument #3 (string expected, got Instance)?

Hello! When I run my script, it gives me the output invalid argument #3 (string expected, got Instance). Does anyone have any idea how this occurred and how I can fix it?

Here is a short summary of what I’m trying to do.

When a TextButton is clicked, it should get the Text out of a TextBox, and put the textbox text into a TextLabel, for an announcement sort of thing. I am using a remote event to do this.

Fire Script: (The script that fires the remote event)

local event = game.ReplicatedStorage.Announce
local input = script.Parent.Parent.InputText
local announcetext = script.Parent.Parent.Parent.TextLabel

script.Parent.MouseButton1Click:Connect(function()
	input.Text = "Announcing your message.. please wait."
	input.TextEditable = false
	wait(2)
	event:FireServer(input,announcetext)
	input.Parent.Visible = false
	script.Parent.Parent.Parent.AdminPanelGui.Visible = true
	input.TextEditable = true
end)

And here is the Server script: (The stuff that the remote event should do)

local Event = game.ReplicatedStorage:WaitForChild("Announce")

Event.OnServerEvent:Connect(function(input,announcetext)
	announcetext.Text = input
end)

The error is apparently going wrong at announcetext.Text = input according to the debug.

This is pretty self explanatory! input is clearly an instance! Try doing
announcetext.Text = input.Text

3 Likes

announcetext.Text = input should be announcetext.Text = input.Text

2 Likes

It gave me the following error.
image

1 Like

No need to post the same thing twice. That’s because when receiving events from the server, the first argument would always be the Player that fired the event!

try:

Event.OnServerEvent:Connect(function(Player,input,announcetext)
	announcetext.Text = input.Text
end)

5 Likes

You forgot to include the .Text after input, so the server script would actually be:

local Event = game.ReplicatedStorage.Announce

Event.OnServerEvent:Connect(function(Player, input, announcetext)
	announcetext.Text = input.Text
end)

Another tip: WaitForChild isn’t necessary for objects in ReplicatedStorage because they’re already loaded in by the time scripts in ServerScriptService run.

1 Like

Ah sorry about that, lemme correct that.

2 Likes

Server Script:

local Event = game.ReplicatedStorage:WaitForChild("Announce")

Event.OnServerEvent:Connect(function(player,input,announcetext)
	announcetext.Text = input
end)

Client:

local event = game.ReplicatedStorage.Announce
local input = script.Parent.Parent.InputText
local announcetext = script.Parent.Parent.Parent.TextLabel

script.Parent.MouseButton1Click:Connect(function()
	input.Text = "Announcing your message.. please wait."
	input.TextEditable = false
	wait(2)
	event:FireServer(input.Text,announcetext)
	input.Parent.Visible = false
	script.Parent.Parent.Parent.AdminPanelGui.Visible = true
	input.TextEditable = true
end)

I’m not sure if it works, I haven’t tested it out.

4 Likes