Need help with story GUI

You see, I’m having trouble with the dialogue GUI for my story game.

The script in ServerScriptService:

local status = game.ReplicatedStorage:WaitForChild("Status")
local dialogueEv = game.ReplicatedStorage.RemoteEvents.GuiEvents.Dialogue
local toggleDialogue = game.ReplicatedStorage.RemoteEvents.ToggleEvents.ToggleDialogue

local Npc = game.Workspace.NPC.Mike
local NpcImg = "rbxassetid://2128423326"
local NpcName = Npc.Name
local NpcFace = Npc.Head.face

local playerName
local playerImg

local function randomPlayer()
	local players = game.Players:GetPlayers()
	local playerNumber = math.random(1, #players)
	
	local chosen = players[playerNumber]
	
	playerImg = game.Players:GetUserThumbnailAsync(chosen.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	playerName = chosen.Name
end

wait(3)
dialogueEv:FireAllClients("Testing, Testing. 1, 2, 3...")

The local script in the dialogue screen GUI:

local toggleDialogue = game.ReplicatedStorage.RemoteEvents.ToggleEvents.ToggleDialogue

toggleDialogue.OnClientEvent:Connect(function(toggle)
	
	if toggle == true then
		script.Parent.Frame.Visible = true
	else
		if toggle == false then
			script.Parent.Frame.Visible = false
		end
	end
	
end)

The local script in a folder in StarterGui:

local player = game.Players.LocalPlayer

local dialogueEv = game.ReplicatedStorage.RemoteEvents.GuiEvents.Dialogue
local Frame = player.PlayerGui:WaitForChild("Dialogue").Frame

dialogueEv.OnClientEvent:Connect(function(PlayerImage, PlayerName, Dialogue)
	Frame.Visible = true
	Frame:WaitForChild("TextLabel").Text = PlayerName
	Frame:WaitForChild("Player").Image = PlayerImage
	for ticker = 1, #Dialogue, 1 do
		Frame:WaitForChild("Ticker").Text = string.sub(Dialogue, 1, ticker)
		wait(0.04)
	end
end)

Error I keep getting:

The error is coming from the script above. Any suggestions on how I can fix this?

In the server-sided script, you call the RemoteEvent with a single string argument.

dialogueEv:FireAllClients("Testing, Testing. 1, 2, 3...")

Despite that, your client sided event handler seems to expect three parameters.

dialogueEv.OnClientEvent:Connect(function(PlayerImage, PlayerName, Dialogue)

Your string “Testing, Testing. 1, 2, 3…” is being passed into PlayerImage and PlayerImage alone, resulting in the values of PlayerName and Dialogue being nil.

1 Like

I understand. So how can I fix the function?

Well, this is all essentially dependent on how you want your dialogue system to run.
If you’re just trying to do a simple test, replace the server script with the following code:

local status = game.ReplicatedStorage:WaitForChild("Status")
local dialogueEv = game.ReplicatedStorage.RemoteEvents.GuiEvents.Dialogue
local toggleDialogue = game.ReplicatedStorage.RemoteEvents.ToggleEvents.ToggleDialogue

local Npc = game.Workspace.NPC.Mike
local NpcImg = "rbxassetid://2128423326"
local NpcName = Npc.Name
local NpcFace = Npc.Head.face

local playerName
local playerImg

local function randomPlayer()
	local players = game.Players:GetPlayers()
	local playerNumber = math.random(1, #players)
	
	local chosen = players[playerNumber]
	
	playerImg = game.Players:GetUserThumbnailAsync(chosen.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	playerName = chosen.Name
end

wait(3)
randomPlayer()
dialogueEv:FireAllClients(playerImg, playerName, "This is a test dialogue.")

The code behind this should be pretty self-explanatory, but if you would like me to explain anything in more detail, let me know.

1 Like

Thanks, but I want the image of an NPC, but I did that in another topic.

Still, thanks for your help!