Bug on text changing?

Hello devforum! I was trying to make a dialogue system like Fisch, but I stumbled upon a bug in the code. Whenever I try to change the textlabel text to the desired one, the text changed AFTER the code ran (when the billboardgui was hidden), ive tried multiple solutions, but none of them worked. Heres a slice of code from the module I created, I will provide more if needed:

local function TypeDialogue(textlabel : TextLabel, text : string, speed : number)
	for i = 1, #text do
		textlabel.Text = string.sub(text, 1, i)
		task.wait(speed)
	end
end


function module.ShowDialogue(npc : Model, plr : Player, object : BillboardGui, textlabel : TextLabel, text : string, speed : number)
	if not npc or not plr or not object then
		warn("No NPC/Player/UI!")
		return
	else
		local dialogue = object:Clone()
		dialogue.Parent = npc.Head
		dialogue.Enabled = true
		TypeDialogue(textlabel, text, speed)
	end
end

Can someone tell me why this happens? Thanks in advance! (sorry if the code is a bit silly, im still a beginner and i tried making up my own ideas)

1 Like

Try a pause after you set the path to the new textlabel..

local rs = game:GetService("RunService")
--
local newTextLabel = dialogue:FindFirstChild("TextLabel", true)
        
        -- Wait for the next physics step (GUI is ready)
        rs.Stepped:Wait()
        
        -- Now type
        TypeDialogue(newTextLabel, text, speed)

I like stepped myself and it fits here, but this could be task.wait() too or task.wait(whatever).

This worked perfectly! Thank you so much!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.