String expected got nil?

Hey I’m getting this weird error and I may be just stupid but I can’t seem to find the error…?

error:

Code:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Argument = ReplicatedStorage.Argument
local TypeWriter = require(ReplicatedStorage.TypeWriter)

local GingerbreadsValue = script.Parent.GingerFrame.Gingerbreads

function Comma(amount)
	local formatted = amount
	while true do  
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if (k==0) then
			break
		end
	end
	return formatted
end

local Player = Players.LocalPlayer

Player.DataFolder.Gingerbreads:GetPropertyChangedSignal("Value"):Connect(function()
	TypeWriter.Type(GingerbreadsValue, Comma(Player.DataFolder.Gingerbreads.Value))
end)

Argument.OnClientEvent:Connect(function(Arg)
	if not Arg then return end
	if Arg == "PlayerJoinChangeValues" then
		GingerbreadsValue.Text = TypeWriter.Type(GingerbreadsValue, Comma(Player.DataFolder.Gingerbreads.Value)) -- error line
	end
end)

Thanks in advance!

Can you explain what the script is actually doing?
also what are comma and TyperWriter

Comma makes the numbers go from 1000 to 1,000

The typewriter is just a cool addon which writes the text (as if you’re writing it on a paper)
like H-E-L-L-O

local TypeWriter = {}

TypeWriter.Type = function(Object, Text)
	for i = 1, #Text, 1 do
		Object.Text = string.sub(Text, 1, i)
		wait(0.005)
	end
end

return TypeWriter

Unless “Player.DataFolders.Gingerbreads.Value” itself is nil, It’s either the Typewriter or Comma breaking weirdly.

Try with only the typewriter, then with only the comma, and then just with neither of them to try to track down the bug that way

if the error is here then you are missing a third argument(string) in the TypeWriter.Type function
which is basically what the error says

right now you only have two arguments

Module scripts are often confused on how to use them by many developers, its better to do the script below, as incase of any lag, or slow internet of player, the text might get stuck too, this script runs in client, and this may take upto 50 kb of client memory usage, it does not lag too

Use this local script:

local function typewritier(texttotype,textlabel)
   textlabel.Text = "" -- clears textlabel text
   for i = 1,#texttotype do -- # means length of something, here it means length of text
     task.wait(0.05)
     textlabel.Text = textlabel.Text..string.sub(texttotype,i,i)
  end
end

-- how to run it
typewritier("Hello, this is a testing message",textlabel) -- first is your string, second is your instance(object) textlabel

This works

2 Likes
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Argument = ReplicatedStorage.Argument
local TypeWriter = require(ReplicatedStorage.TypeWriter)

local GingerbreadsValue = script.Parent.GingerFrame.Gingerbreads

function Comma(amount)
	local formatted = amount
	while true do  
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if (k==0) then
			break
		end
	end
	return formatted
end

local Player = Players.LocalPlayer

Player.DataFolder.Gingerbreads:GetPropertyChangedSignal("Value"):Connect(function()
	TypeWriter.Type(GingerbreadsValue, Comma(Player.DataFolder.Gingerbreads.Value))
end)

Argument.OnClientEvent:Connect(function(Arg)
	if not Arg then return end
	if Arg == "PlayerJoinChangeValues" then
		GingerbreadsValue.Text = tostring(TypeWriter.Type(GingerbreadsValue, Comma(Player.DataFolder.Gingerbreads.Value))) -- error line
	end
end)

using tostring() won’t fix the problem

the error occurs because the third argument for TypeWriter.Type is nil

this should work

function intToString(int)
	local thingToChange1 = string.reverse(tostring(int))
	local thingToChange2 = string.split(thingToChange1,'')
	local End = ''
	if #thingToChange2 > 3 then
		for i,v in ipairs(thingToChange2) do
			if i%3 == 0 then
				End=End..v..','
			else
				End=End..v
			end
		end
	else
		End = table.concat(thingToChange2)
	end
	
	return string.reverse(End)
end

i made my intToString and it workd

they already made a comma function, the problem is the typewriter function

I would use a function like what @Deadwoodx showed, this way the text will actually update overtime(which is something the original code didn’t do)

1 Like