Player dialogue GUI didn't work

I’m trying to make a player dialogue GUI its similar to this
image
but instead of changing to a random player like the picture up there
it didn’t even turn into a player like this:
https://gyazo.com/979c27f589c79474ae875404b85571f5
a random player should say “Yay!” but instead the teacher said it
script:

DialogueScript:

local StarterGui = game:GetService("StarterGui")

local createDialogueEvent = game.ReplicatedStorage.Remotes.createDialogueEvent
local hideDialogueEvent = game.ReplicatedStorage.Remotes.hideDialogueEvent
local setDialogueImageEvent = game.ReplicatedStorage.Remotes.setDialogueImageEvent

local richText = require(game.ReplicatedStorage.Modules.RichText)

local player = game.Players.LocalPlayer
local dialogueFrame = player.PlayerGui.MainGui.DialogueFrame

local function swooshSound()
	local sound = Instance.new("Sound",game.ReplicatedStorage)
	sound.PlaybackSpeed = 1
	sound.Volume = 1
	sound.PlayOnRemove = true
	sound.SoundId = "rbxassetid://4845387138"
	sound:Destroy()
end

hideDialogueEvent.OnClientEvent:Connect(function()
	
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	
	swooshSound()
	dialogueFrame:TweenPosition(UDim2.new(0.5,0,2,0),.1)
end)

createDialogueEvent.OnClientEvent:Connect(function(english,spanish)
	if dialogueFrame.Position ~= UDim2.new(0.5,0,0.85,0) then
		
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		
		dialogueFrame:TweenPosition(UDim2.new(0.5,0,0.85,0),.1)
		
	end
	
	local ln = game:GetService("LocalizationService").RobloxLocaleId
	local content = english
	if ln == "en-us" then
		content = english
	elseif ln == "es-es" then
		if spanish then
			content = spanish
		end
	end
	
	local textObject = richText:New(dialogueFrame.textFrame, content)
	textObject:Animate(true)
end)

-- Viewport Script Starts Here

local function cleanVPF()

	if dialogueFrame.ViewportFrame:FindFirstChildOfClass("Model") then
		dialogueFrame.ViewportFrame:FindFirstChildOfClass("Model"):Destroy()
	end

	if dialogueFrame.ViewportFrame:FindFirstChildOfClass("Camera") then
		dialogueFrame.ViewportFrame:FindFirstChildOfClass("Camera"):Destroy()
	end

end

setDialogueImageEvent.OnClientEvent:Connect(function(charName,color)

	dialogueFrame.nameLabel.TextColor3 = color
	dialogueFrame.nameLabel.Text = charName

	local vpCharacter = game.Workspace:FindFirstChild(charName)
	if vpCharacter then
		
		cleanVPF()
		
		local obj = vpCharacter:Clone()
		obj.Parent = dialogueFrame.ViewportFrame
		
		local cam = Instance.new("Camera")
		cam.Parent = dialogueFrame.ViewportFrame
		
		cam.CFrame = CFrame.new(obj.Head.Position + (obj.PrimaryPart.CFrame.lookVector*2), obj.Head.Position)
		
		dialogueFrame.ViewportFrame.CurrentCamera = cam
		
	else
		warn(charName .. " is not in ReplicatedStorage")
	end
	
end)

MainScript:

local createDialogueEvent = game.ReplicatedStorage.Remotes.createDialogueEvent
local hideDialogueEvent = game.ReplicatedStorage.Remotes.hideDialogueEvent
local setDialogueImageEvent = game.ReplicatedStorage.Remotes.setDialogueImageEvent

local randomPlayername
local randomplayerid

local function getPlayerImage(player_id)
	local content, isReady = game:GetService("Players"):GetUserThumbnailAsync(player_id, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	return content
end

local function getRandomPlayer()
	local players = game.Players:GetPlayers()
	local number = math.random(1,#players)
	local randomplayers = players[number]
	randomPlayername = randomplayers.Name
	randomplayerid = randomplayers.UserId
end

wait(10)

setDialogueImageEvent:FireAllClients("Teacher", Color3.new(0, 0.384314, 1))

createDialogueEvent:FireAllClients("")

wait(0.5)

createDialogueEvent:FireAllClients("Hello!")

wait(2)

createDialogueEvent:FireAllClients("I'm Stephen Your teacher and today is a very special day for us Because today we are going Camping!")

wait(3)

setDialogueImageEvent:FireAllClients(getRandomPlayer(randomplayerid, randomPlayername) , Color3.new(0, 0.384314, 1))

createDialogueEvent:FireAllClients("Yay!")

Error:

Players.dirtandra123.PlayerGui.MainGui.DialogueScript:69: invalid argument #3 (string expected, got nil)

Any solutions??

What is near line 69? We need to know the code to find the error.

dialogueFrame.nameLabel.Text = charName

You only got 2 parameters in your DialogScript, while the other one:

You got 3 parameters? (Plus that getRandomPlayer function which results as a nil value), I’m guessing it’s cause in this function here:

My guess is that since it’s local, it’ll return back as nil so could you try removing that?

I put it in normal script while Dialoguescript is a local script

I meant changing the local function to a regular function, if that doesn’t work could you add some print() statements to define what charName is supposed to be?

it didn’t work the same as before

Can you try to do:

print(tostring(charName), tostring(color)) 

And send me what it printed?

Teacher 0, 0.384314, 1
1 Like

And the error is on the line with namelabel.Text = charName?
Can you send me image of the Frame how it looks like in StarterGui?

image

I mean Gui set up.
Like: ScreenGui
->Frame
–>TextLabel
etc.

image

Can you try to do

nameLabel.Text = tostring(charName) 

still the same
Argument 1 missing or nil
on line 72

local vpCharacter = game.Workspace:FindFirstChild(charName)

Is the Character inside the Workspace?
Is it named Teacher?

I want to make random players say “Yay!” the teacher’s part works but not the random player