Dictionary views itself as Nil

Hello, Weird issue i’m having with this line of code:

TS = game:GetService("TweenService")
local Config

local DialougeSystem = {}

function DialougeSystem.TypeWrite(plr ,Text)
	local XAxis = 0
	local YAxis = 0
	
	Config = {
		["Text Size"] = UDim2.new(1 / 50, 0, 1 / 5, 0),
		["Text Offset"] = UDim2.new(0, 0, -1 / 5, 0),
		["Text Speed"] = 10, -- Letters Per Second
		["Text Float Duration"] = 1,
		["Default Tween Information"] = TweenInfo.new(Config["Text Float Duration"], Enum.EasingStyle.Sine,Enum.EasingDirection.Out, 0,false,0),
		["Slow Tween Information"] = TweenInfo.new(Config["Text Float Duration"] / 1.5, Enum.EasingStyle.Sine,Enum.EasingDirection.Out, 0,false,0),
		["Fast Tween Information"] = TweenInfo.new(Config["Text Float Duration"] * 1.5, Enum.EasingStyle.Sine,Enum.EasingDirection.Out, 0,false,0),
	}

Why is Config seen as Nil?

The Config variable isn’t createduntil it gets to the closing }.
Try having all the variables that dont’ try to call config in the initial {}, then have the other ones added after the fact, by doing Config[“Fast Tween Information”] = TweenInfo.new(Config[“Text Float Duration”]… and so on.

1 Like

While you are defining Config,

you are also using Config

Which is what im assuming is the error. Since config isnt defined yet you cant use it. Try defining the first 4 thingy majigys first and then add the ones that rely on config to config after that.

Which would look something like:

function DialougeSystem.TypeWrite(plr ,Text)
	local XAxis = 0
	local YAxis = 0

	Config = {
		["Text Size"] = UDim2.new(1 / 50, 0, 1 / 5, 0),
		["Text Offset"] = UDim2.new(0, 0, -1 / 5, 0),
		["Text Speed"] = 10, -- Letters Per Second
		["Text Float Duration"] = 1,
	}

	Config["Default Tween Information"] = TweenInfo.new(Config["Text Float Duration"], Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
	Config["Slow Tween Information"] = TweenInfo.new(Config["Text Float Duration"] / 1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
	Config["Fast Tween Information"] = TweenInfo.new(Config["Text Float Duration"] * 1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
end
1 Like

Thank you both! Didn’t know the dictionary isnt created until }

1 Like

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