Why isnt the text changing?

Hi,i hope everyone is doing fine.
I have stumbled across this problem when making a dialogue system

Somehow the text prints on the output but when i try to change it on the textbox it wont change
Heres my code:

Read=function(data,MG)
	local gui=MG
	local frame=gui.Frame
	local TextB=script.Parent.DialogueGui.Frame.TextBox
	local Answer1=frame.Answer1
	local Answer2=frame.Answer2
	local Answer3=frame.Answer3	
	for i=1,#data do  --PAIN
		local CData=data[i]

		frame.Transparency=CData.Transparency
		frame.BorderSizePixel=CData.BorderPixel
		local CanContinue=false
		if CData.OpenSpeed==0 then 
			CanContinue=true 
		end
		if CData.OpenSpeed~=0 then
			frame.Size=UDim2.new(0.001,0,0.001,0)
			local Time=CData.OpenSpeed
			local NTween = CreateTween(frame, {Time, CData.EasingStyle, CData.EasingDir, 0, false, 0},{
				Size=UDim2.new(1, 0,0.342, 0),
			}, true)
			NTween.Completed:Connect(function() CanContinue=true end)
		end
		repeat wait() until CanContinue==true
		if CData.Answer==false or CData.Answer==nil then
			TextB.Visible=true
			TextB.TextScaled=CData.TextScaled
			TextB.TextColor3=CData.TextColor
			TextB.TextSize=CData.TextSize
			TextB.Font=CData.TextFont
			TextB.TextStrokeTransparency=CData.TextStrokeTransparency
			TextB.TextStrokeColor3=CData.TextStrokeColor
			print(CData.Text)
			for TextPosition=1,#CData.Text do 
				local CurrentText=string.sub(CData.Text,1,TextPosition)
				print(CurrentText)
				TextB.Text=CurrentText
				wait(CData.Speed or 0)
			end 
			wait(CData.WaitUntilNext)

		end
	end
end
Read(read,script.Parent.DialogueGui)

I believe the problem is in this part?

	for TextPosition=1,#CData.Text do 
				local CurrentText=string.sub(CData.Text,1,TextPosition)
				print(CurrentText)
				TextB.Text=CurrentText
				wait(CData.Speed or 0)
			end 

Shouldn’t be though since the print does print the text properly and TextB isnt nil (i checked),
As you can see here:
whytho
Yet…
whytho2
The Text property wont change.
In fact it turns blank as you can see but in the properties tab on studio it shows that it’s the default text.

Note:this code is inside a local script and im getting the text from a module script (shouldn’t be a problem since it prints).

Its kinda weird cause if i do:

while wait() do script.Parent.DialogueGui.Frame.TextBox.Text=tostring(math.random(0,300)) end 

It works properly as you can see here:
whytho3

Any help would be apreciated :slight_smile:

1 Like

I am not seeing a print for TextB.Text after its been assigned.
I have found it useful when debugging to add the name of the item being printed along with its value. for example print(“TextB.Text=”,TextB.Text)

1 Like

Hi, this may help you solve your problem
First, comment on any code that does not affect the output you expect. This way you can more easily find out what is causing the error. If you still can’t find it, then create a new project and test your code there, with only the minimum to make it work, trying to keep all instances as default as possible. For example, I did this and your code worked correctly.

local Read = function(data, MG)
	local gui=MG
	local frame=gui.Frame
	local TextB=frame.TextBox
	-- local Answer1=frame.Answer1
	-- local Answer2=frame.Answer2
	-- local Answer3=frame.Answer3
	for i=1,#data do  --PAIN
		local CData=data[i]

		-- frame.Transparency=CData.Transparency
		-- frame.BorderSizePixel=CData.BorderPixel
		-- local CanContinue=true--false
		-- if CData.OpenSpeed==0 then
		-- 	CanContinue=true
		-- end
		-- if CData.OpenSpeed~=0 then
		-- 	frame.Size=UDim2.new(0.001,0,0.001,0)
		-- 	local Time=CData.OpenSpeed
		-- 	local NTween = CreateTween(frame, {Time, CData.EasingStyle, CData.EasingDir, 0, false, 0},{
		-- 		Size=UDim2.new(1, 0,0.342, 0),
		-- 	}, true)
		-- 	NTween.Completed:Connect(function() CanContinue=true end)
		-- end
		-- repeat wait() until CanContinue==true
		if CData.Answer==false or CData.Answer==nil then
			TextB.Visible=true
			-- TextB.TextScaled=CData.TextScaled
			-- TextB.TextColor3=CData.TextColor
			-- TextB.TextSize=CData.TextSize
			-- TextB.Font=CData.TextFont
			-- TextB.TextStrokeTransparency=CData.TextStrokeTransparency
			-- TextB.TextStrokeColor3=CData.TextStrokeColor
			print(CData.Text)
			for TextPosition=1,#CData.Text do 
				local CurrentText=string.sub(CData.Text,1,TextPosition)
				print(CurrentText)
				TextB.Text=CurrentText
				wait(CData.Speed or 0)
			end 
			-- wait(CData.WaitUntilNext)

		end
	end
end
Read({{Text = "Some Text"}},script.Parent:WaitForChild("DialogueGui"))

image

1 Like

Im sorry for the very late answer,thank you that solved it! The problem was with the text color :sweat_smile: