You see, I’m working on this story game. I want my picture GUI in the dialogue to switch from the viewport to the player speaking.
Here’s the script I provided 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
local function playerToNPC(viewport, img)
viewport = game.StarterGui.Dialogue.Frame.ViewportFrame
img = game.StarterGui.Dialogue.Frame.Player
img.Visible = false
viewport.Visible = true
end
local function NPC_ToPlayer(viewport, img)
viewport = game.StarterGui.Dialogue.Frame.ViewportFrame
img = game.StarterGui.Dialogue.Frame.Player
img.Visible = true
viewport.Visible = false
end
wait(3)
playerToNPC()
dialogueEv:FireAllClients(NpcImg, NpcName, "This is a test dialogue.")
wait(3)
NPC_ToPlayer()
randomPlayer()
dialogueEv:FireAllClients(playerImg, playerName, "Ok, ok then :)")
And here’s the local script that’s 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)
Problem: the picture only stays on the NPC when a player is talking. I’m pretty sure the issue is coming from the first script above.
Any suggestions on how to debug this?