Invalid argument #3 (string expected, got Instance)

Hey, I’m trying to make a dialog script but while running it this error shows in the output.

Error:

Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Player = game.Players.LocalPlayer
local DialogEvent = ReplicatedStorage.Events.GuiEvents:FindFirstChild("DialogEvent")
local Frame = Player.PlayerGui:WaitForChild("Dialog").Frame

local function AnimateText(Dialog)
	for i = 1, #Dialog, 1 do
		Frame:WaitForChild("Dialog").Text = string.sub(Dialog, 1, i)
		wait()
	end
end

DialogEvent.OnClientEvent:Connect(function(Image, Name, Dialog)
	Frame.Visible = true
	Frame:WaitForChild("Image").Image = Image
	Frame:WaitForChild("Name").Text = Name
	AnimateText(Dialog)
end)
1 Like

This means that your dialog is not a string. Could you send me your code to call this event?

1 Like

image

1 Like

Can you also include the part of the code where you have the dialog variable?

1 Like

1 Like

have you try

Frame:WaitForChild("Dialog").Text = string.sub(Dialog.Text, 1, I)
1 Like

The capitalized i is invalid in the script.

1 Like

are you trying to make a Typewriter Effect if so

this might interest you

and make the i in my responce lowercase maybe

1 Like

I can’t see anything obvious so I would suggest print the variables obtained from server and letting us know what is up

1 Like

Actually this may be it:

can you verify if the Image parameter on server (FireAllClients) is the Image.Image of the image?

1 Like

Could you clarify a bit more on this?

1 Like
Frame:WaitForChild("Image").Image = Image

this is where its erroring because

DialogEvent.OnClientEvent:Connect(function(Image, Name, Dialog)

Image parameter obtained is an actual Image instance, not the Image assetid,

Frame:WaitForChild("Image").Image = Image

.Image requires a string value for the image assetid

this is what I’m led to believe

1 Like

Okay so that’s the function for the fire all clients so how would I add the string value?

1 Like

Can you send me the entire declaration of variable NpcImage and PlayerImage via text

To add, all you would have to do is take the Image’s .Image and set the NpcImage to it

I believe PlayerImage should be fine? I’m not sure until you test it since NpcImage is whats causing the error I think and so idk if its functional or not

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DialogEvent = ReplicatedStorage.Events.GuiEvents:FindFirstChild("DialogEvent")
local ToggleDialogEvent = ReplicatedStorage.Events.ToggleEvents:FindFirstChild("ToggleDialogEvent")

local Npc = game.Workspace.Npcs:FindFirstChild("Crazy")
local NpcImage = "rbxassetid://6306615077"
local NpcName = Npc

local PlayerImage
local PlayerName

local function RandomPlayer()
	local Players = game.Players:GetPlayers()
	local RandomPlayer = math.random(1, #Players)
	local ChosenPlayer = Players[RandomPlayer]
	
	PlayerImage = game.Players:GetUserThumbnailAsync(ChosenPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	PlayerName = ChosenPlayer.Name
end

local function Part1()
	DialogEvent:FireAllClients(NpcImage, NpcName, "Hi, I'm Crazy, but that's just my name. I'm not actually crazy...")
	wait(5)
	RandomPlayer() DialogEvent:FireAllClients(PlayerImage, PlayerName, "What's that cave by the cabin?")
	wait(5)
	DialogEvent:FireAllClients(NpcImage, NpcName, "I don't know, but there is a sign that says to not enter.")
	wait(5)
	RandomPlayer() DialogEvent:FireAllClients(PlayerImage, PlayerName, "Oh okay, is that the cabin were going to be sleeping in?")
	wait(5)
end

wait(10)
Part1()
1 Like

Ok so it looks like it is infact playerimage messing up, npcimage is an assetid, instead you will need to send the player’s UserId to clients instead:

--WHEN SENDING PLAYER STUFF
DialogEvent:FireAllClients(nil, PlayerName, "What's that cave by the cabin?", PlayerId)
--NPC STAYS SAME
--DialogEvent:FireAllClients(NpcImage, NpcName, "Hi, I'm Crazy, but that's just my name. I'm not actually crazy...")
	

then in client:

DialogEvent.OnClientEvent:Connect(function(Image, Name, Dialog, PlayerId)
	Frame.Visible = true
        if Image then
	Frame:WaitForChild("Image").Image = Image
        else
        Frame:WaitForChild("Image").Image=game.Players:GetUserThumbnailAsync(PlayerId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
        end
	Frame:WaitForChild("Name").Text = Name
	AnimateText(Dialog)
end)

This should solve your issue, if it does please mark it as solution

1 Like

Alright so how would I implement it though since the script I just sent is in ServerScriptService while the other script in the topic is in StarterGui as a local script.

1 Like

you obtain the player’s UserId and change PlayerImage to PlayerId
PlayerId=ChosenPlayer.UserId

and then copy and paste when a player is talking

DialogEvent:FireAllClients(nil, PlayerName, "What's that cave by the cabin?", PlayerId)

and then copy paste this

DialogEvent.OnClientEvent:Connect(function(Image, Name, Dialog, PlayerId)
	Frame.Visible = true
        if Image then
	Frame:WaitForChild("Image").Image = Image
        else
        Frame:WaitForChild("Image").Image=game.Players:GetUserThumbnailAsync(PlayerId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
        end
	Frame:WaitForChild("Name").Text = Name
	AnimateText(Dialog)
end)

If still some sort of error, can set nil to false but it should function

1 Like

Alright thanks, I have to go right now, but I’ll test this later.

2 Likes