Unable to assign property Value. string expected, got nil (Iterating)

Hello, I have a problem, kindly help me. (Sorry if there is any grammar problem)

  1. What do you want to achieve? I want to Iterate a table to a TextLabel, (error line will be highlighted with --> <-- ) and for the rest of the script to carry on.

  2. What is the issue? I am looking to iterate the TextLabel with '/', '-', '\\', '|', but not as I expected, I got an error Unable to assign property Value. string expected, got nil as I did not sign any nil value to the TextLabel!

  3. What solutions have you tried so far? Devforum, script-testing, and my own prior scripting knowledge.

Here’s my script (LocalScript), I put it in ReplicatedFirst and the descendants of the script has a Gui instance named Loader with the child descendant TextLabel named Sprite.

LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")

ReplicatedFirst:RemoveDefaultLoadingScreen()

local Assets = game:GetDescendants()

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local Common = script.Parent.Common
local P = require(Common.Logger)

P.Log("Startup", "Loading assets & scripts, hold on user!")



repeat task.wait() until game:IsLoaded()

local Loader = script.Loader:Clone()
Loader.Parent = PlayerGui
Sp = false

for i = 1, #Assets do 
	local asset = Assets[i]
	local Sprites = {
		["/"] = "-",
		["-"] = "\\",
		["\\"] = "|"
	}
	ContentProvider:PreloadAsync({
		asset
	})
	if Sp == true then
		--> Loader.Sprite.Text = Sprites[Loader.Sprite.Text] <--
	elseif Sp == false then
		Loader.Sprite.Text = '/'
		Sp = true
	end
	Loader.Stat2.Text = '::' .. asset.Name
end

P.Log("Startup", "Scripts and Assets loaded!")

Loader:Destroy()

This is how I test the error:

ErrorTest
print(Sprites[Loader.Sprite.Text]) -- Not a nil, but got an error, or maybe im stupid.

The only issue I get in the output is Unable to assign property Value. string expected, got nil as I didn’t assign a nil value to Loader.Sprite.Text, and kind of confused what to do.

Thanks.

Can you try move

local Assets = game:GetDescendants()

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local Common = script.Parent.Common
local P = require(Common.Logger)

after

repeat task.wait() until game:IsLoaded()

?

It won’t work still…

Still gives me the error, any other help?

Instead put this:
Replace with a foreach:

for _,asset in pairs(Assets) do

Alright, let me try that…

Hold on.

It still won’t work.

The problem is in this snippet


for _, asset in pairs(Assets) do 
	local Sprites = {
		["/"] = "-",
		["-"] = "\\",
		["\\"] = "|"
	}
	ContentProvider:PreloadAsync({
		asset
	})
	if Sp == true then
		Loader.Sprite.Text = Sprites[Loader.Sprite.Text] -- This bad boy
	elseif Sp == false then
		Loader.Sprite.Text = '/'
		Sp = true
	end
	Loader.Stat2.Text = '::' .. asset.Name
end

and this:

for _,asset in pairs(Assets) do
	ContentProvider:PreloadAsync({
		asset
	})
	Loader.Sprite.Text = "/"
	if Sp == true then
		Loader.Sprite.Text = Sprites[Loader.Sprite.Text]
	elseif Sp == false then
		Loader.Sprite.Text = "/"
		Sp = true
	end
	Loader.Stat2.Text = '::' .. asset.Name
end

Remove that:

repeat task.wait() until game:IsLoaded()

Why put this line while the script already loading all assets?

I don’t know, I followed a tutorial how to make a loading screen in ReplicatedService and added my own stuff, the tutorial included

repeat task.wait() until game:IsLoaded()

If I removed the line still doesn’t fix the problem, I already mentioned where the line error at.

I have a solution i guess:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
local Common = script.Parent.Common
local P = require(Common.Logger)

ReplicatedFirst:RemoveDefaultLoadingScreen()
P.Log("Startup", "Loading assets & scripts, hold on user!")

repeat task.wait() until game:IsLoaded()

local Assets = game:GetDescendants()
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local Sprites = {
	["/"] = "-",
	["-"] = "\\",
	["\\"] = "|"
}
local Loader = script.Loader:Clone()
local Sp = false
local passed = 0
Loader.Parent = PlayerGui

for _,asset in pairs(Assets) do
	ContentProvider:PreloadAsync({
		asset
	})
	Loader.Sprite.Text = "/"
	if Sp == true then
		Loader.Sprite.Text = Sprites[Loader.Sprite.Text]
	elseif Sp == false then
		Loader.Sprite.Text = "/"
		Sp = true
	end
	Loader.Stat2.Text = '::' .. asset.Name
	passed += 1
end
repeat wait() until passed==#Assets
Loader:Destroy()

P.Log("Startup", "Scripts and Assets loaded!")
1 Like

Let me try that and replace my original script.

i guess the script destroy Loader while there are the loading

It works! Thank you so much fares!

1 Like

You are welcome! I am happy to have helped you!

1 Like

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