My issue that I’m running in to currently is with Text Labels. The text within the properties of the Text Label show that they are blank, which is what I want. In the videos posted below, you will see that when the UI is Enabled through the script after the tweening of the Player’s camera, there is a frame where the last used Text is inserted into the Text Label, as well as the last NPCs Name being inserted into the other Text Label. If the UI is enabled fully throughout the entire process, this doesn’t happen. It works how it is supposed to. Another odd thing I found is that if I have the TextLabel selected in the Explorer, even if the ‘Enabled’ property is being controlled by the script, it still works the way it is supposed to. In the scripts I provide below, you will see countless ways I’ve tried to fix the problem (basically just setting the Text to nothing).
Video of the Issue:
Video of how it should Look:
It might be hard to see in the first clip, since it is only there for one frame, so here is the screenshot of the issue:
Below is my Local Script:
local npcFolder = workspace:FindFirstChild("NPCs")
local dialogueModule = require(script.DialogueModule)
local npcDialogueModule = require(script.NPCDialogue)
local tweenService = game:GetService("TweenService")
local debris = game:GetService("Debris")
local uis = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local plrValues = plr:WaitForChild("Player Values")
local plrTalkingToNPC = plrValues:FindFirstChild("PlayerTalkingToNPC")
local plrModule = require(plr.PlayerScripts:WaitForChild('PlayerModule'))
local plrControls = plrModule:GetControls()
local npcsTalkedTo = plr:WaitForChild("NPCsTalkedTo")
local plrUI = plr.PlayerGui
local npcUI = plrUI:WaitForChild("NPCUI")
local currentCamera = workspace.CurrentCamera
local dialogueIndex = 1
local npcDialogueFinished = true
local renderCamConnection
local mouseClickConnection
for _, npc in npcFolder:GetChildren() do
local npcValues = npc:FindFirstChild("Values")
local plrCamCFrame = npcValues:FindFirstChild("PlayerCamCFrame")
npc.ClickDetector.MouseHoverEnter:Connect(function()
if plrTalkingToNPC.Value == false then
npc.Highlight.Enabled = true
end
end)
npc.ClickDetector.MouseHoverLeave:Connect(function()
if plrTalkingToNPC.Value == false then
npc.Highlight.Enabled = false
end
end)
npc.ClickDetector.MouseClick:Connect(function()
if plrTalkingToNPC.Value == false then
plrTalkingToNPC.Value = true
plrControls:Disable()
npc.Highlight.Enabled = false
npc.ClickDetector.MaxActivationDistance = 0
plrCamCFrame.Value = currentCamera.CFrame
npcUI.Main.NPCName.Text = npc.Name
npcUI.Main.DialogFrame.NPCDialog.Text = ""
dialogueModule.tweenCamIn(npc, currentCamera, tweenService)
renderCamConnection = game:GetService("RunService").RenderStepped:Connect(function()
dialogueModule.renderNewCam(npc, currentCamera)
end)
print(npcUI.Main.DialogFrame.NPCDialog.Text)
npcUI.Enabled = true
npcUI.Main.DialogFrame.Option1.MouseEnter:Connect(function()
npcUI.Main.DialogFrame.Option1.BackgroundTransparency = 0.5
end)
npcUI.Main.DialogFrame.Option1.MouseLeave:Connect(function()
npcUI.Main.DialogFrame.Option1.BackgroundTransparency = 1
end)
npcUI.Main.DialogFrame.Option2.MouseEnter:Connect(function()
npcUI.Main.DialogFrame.Option2.BackgroundTransparency = 0.5
end)
npcUI.Main.DialogFrame.Option2.MouseLeave:Connect(function()
npcUI.Main.DialogFrame.Option2.BackgroundTransparency = 1
end)
--// Begin the dialogue.
if not npcsTalkedTo:FindFirstChild(npc.Name) then
print("Test NPCCCCC")
dialogueModule.npcDialog(npcUI.Main.DialogFrame.NPCDialog, npcDialogueModule[npc.Name]["Greetings"][dialogueIndex], 0.025, false, npcUI, debris)
dialogueIndex += 1
mouseClickConnection = uis.InputBegan:Connect(function(key, GPE)
if GPE then return end
if key.UserInputType == Enum.UserInputType.MouseButton1 then
if dialogueIndex <= #npcDialogueModule[npc.Name]["Greetings"] and npcDialogueFinished == true then
npcDialogueFinished = false
dialogueModule.npcDialog(npcUI.Main.DialogFrame.NPCDialog, npcDialogueModule[npc.Name]["Greetings"][dialogueIndex], 0.025, false, npcUI, debris)
dialogueIndex +=1
npcDialogueFinished = true
elseif dialogueIndex == #npcDialogueModule[npc.Name]["Greetings"] + 1 then
if not npcsTalkedTo:FindFirstChild(npc.Name) then
local newNPCTalkedTo = Instance.new("StringValue")
newNPCTalkedTo.Name = npc.Name
newNPCTalkedTo.Value = npc.Name
newNPCTalkedTo.Parent = npcsTalkedTo
npcUI.Main.DialogFrame.NPCDialog.Text = ""
npcUI.Main.NPCName.Text = ""
npcUI.Enabled = false
renderCamConnection:Disconnect()
dialogueModule.tweenCamOut(plr, currentCamera, plrCamCFrame, tweenService)
plrControls:Enable()
dialogueIndex = 1
plrTalkingToNPC.Value = false
npc.ClickDetector.MaxActivationDistance = 32
mouseClickConnection:Disconnect()
end
end
end
end)
elseif npcsTalkedTo:FindFirstChild(npc.Name) then
npcUI.Main.NPCName.Text = npc.Name
npcUI.Main.DialogFrame.NPCDialog.Text = ""
dialogueModule.npcDialog(npcUI.Main.DialogFrame.NPCDialog, npcDialogueModule[npc.Name]["Normal"]["Question"], 0.025, false, npcUI, debris)
npcUI.Main.DialogFrame.Option1.Visible = true
npcUI.Main.DialogFrame.Option2.Visible = true
npcUI.Main.DialogFrame.Option1.MouseButton1Click:Connect(function()
npcUI.Main.DialogFrame.Option1.Visible = false
npcUI.Main.DialogFrame.Option2.Visible = false
print("Player has pressed the 1st option, which is: " .. npcUI.Main.DialogFrame.Option1.Text)
dialogueModule.npcDialog(npcUI.Main.DialogFrame.NPCDialog, npcDialogueModule[npc.Name]["Normal"][npcUI.Main.DialogFrame.Option1.Text], 0.025, false, npcUI, debris)
end)
npcUI.Main.DialogFrame.Option2.MouseButton1Click:Connect(function()
npcUI.Main.DialogFrame.Option1.Visible = false
npcUI.Main.DialogFrame.Option2.Visible = false
print("Player has pressed the 1st option, which is: " .. npcUI.Main.DialogFrame.Option2.Text)
dialogueModule.npcDialog(npcUI.Main.DialogFrame.NPCDialog, npcDialogueModule[npc.Name]["Normal"][npcUI.Main.DialogFrame.Option2.Text], 0.025, false, npcUI, debris)
renderCamConnection:Disconnect()
npcUI.Enabled = false
plrTalkingToNPC.Value = false
dialogueModule.tweenCamOut(plr, currentCamera, plrCamCFrame, tweenService)
plrControls:Enable()
end)
end
elseif plrTalkingToNPC.Value == true then
print("Player is already talking to " .. npc.Name)
end
end)
end
Below is the Module Script:
local dialogueModule = {}
function dialogueModule.npcDialog(textLabel, dialog, waitTime, skipDialogue, npcUI, debris)
skipDialogue = false
local sfx = npcUI:WaitForChild("SFX")
for i = 1, #dialog, 1 do
if skipDialogue == true then
local skipSFX = sfx:FindFirstChild("SkipSFX"):Clone()
skipSFX.Parent = script.Parent
skipSFX:Play()
debris:AddItem(skipSFX, skipSFX.TimeLength + 0.05)
textLabel.Text = dialog
skipDialogue = false
return
else
textLabel.Text = string.sub(dialog, 1, i)
local typingSFX = sfx:FindFirstChild("KeyboardSFX1"):Clone()
typingSFX.Parent = script.Parent
typingSFX:Play()
debris:AddItem(typingSFX, typingSFX.TimeLength + 0.05)
wait(waitTime)
end
end
end
function dialogueModule.tweenCamIn(npc, currentCamera, tweenService)
local npcCam = npc:FindFirstChild("Camera")
local twInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local goal = {}
goal.CFrame = CFrame.lookAt(npcCam.Position, npc.Head.Position)
local tweenIn = tweenService:Create(currentCamera, twInfo, goal)
tweenIn:Play()
tweenIn.Completed:Wait()
end
function dialogueModule.tweenCamOut(plr, currentCamera, plrCamCFrame, tweenService)
local twInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local goal = {}
goal.CFrame = plrCamCFrame.Value
local tweenOut = tweenService:Create(currentCamera, twInfo, goal)
tweenOut:Play()
tweenOut.Completed:Wait()
currentCamera.CameraType = Enum.CameraType.Custom
currentCamera.CameraSubject = plr:FindFirstChild("Humanoid")
end
function dialogueModule.renderNewCam(npc, currentCamera)
local npcCam = npc:FindFirstChild("Camera")
currentCamera.CFrame = CFrame.lookAt(npcCam.Position, npc.Head.Position)
end
function dialogueModule.beginDialogue(npc, npcUI)
npcUI.Enabled = true
npcUI.Main.NPCName.Text = npc.Name
end
return dialogueModule
Is there anyway I can insure that it will remain blank? Any reason why it actually never shows that text in the TextLabel, but still reappears?
Thank you!