Unable to assign property Value. string expected, got nil

Hello everyone, I was making the datastore script of my loadout system. Recently, I noticed a error that said, “Unable to assign property Value. string expected, got nil” in line 42.

Here’s a script:

local onJoinTable = {
	[true] = function(player, result)
		print("No data has found")
		local LoadoutClass = require(script.LoadoutClass).new(player)
		loadoutclass[Players:GetUserIdFromNameAsync(player.Name)] = LoadoutClass
		-- loadoutclass
		local KeybindSetup = require(script.KeybindSetup).new(player)
		keybindclass[Players:GetUserIdFromNameAsync(player.Name)] = KeybindSetup
		
		print(LoadoutClass)
	end,

	[false] = function(player, result)
		print("Player data has found")
		local LoadoutClass = require(script.LoadoutClass).new(player, HttpService:JSONDecode(result))
		local KeybindSetup = require(script.KeybindSetup).new(player, HttpService:JSONDecode(result))
		LoadoutClass:SetCharacter(player.Character)
		LoadoutClass:SetName(player.Name)
		
		player.KeybindsFolder.OpenSettings.Value = KeybindSetup.OpenSettings
		player.LoadoutFolder.NationName.Value = LoadoutClass.NationName -- the error
		player.LoadoutFolder.RegimentName.Value = LoadoutClass.RegimentName
		player.LoadoutFolder.IsAssigned.Value = LoadoutClass.IsAssigned
		
		task.wait()
		player:LoadCharacter()
		print(LoadoutClass)

		loadoutclass[Players:GetUserIdFromNameAsync(player.Name)] = LoadoutClass
		keybindclass[Players:GetUserIdFromNameAsync(player.Name)] = KeybindSetup
	end,
}

After finishing the code, the error appear when I start to join. Then, when I rejoined back, I still keep seeing the same error again. I would appreciate anyone who decides to fix it.

1 Like

Which line in this script that you have provided here is line 42? Edit: I just notice that you added error lol

1 Like

What type of value would be your “NationName” be if I mind asking?

1 Like
function LoadoutClass.new(player, self)
	repeat task.wait() until player.Character ~= nil
	if self then return setmetatable(self, LoadoutClass) end
	local self = setmetatable({}, LoadoutClass)
	self.Character = player.Character
	self.NationName = player.LoadoutFolder.NationName.Value
	self.RegimentName = player.LoadoutFolder.RegimentName.Value
	self.IsAssigned = player.LoadoutFolder.IsAssigned.Value
	self.Name = player.Name
	
	return self
end
1 Like

Maybe try creating the table before you setmetatable, could maybe be a fix but am not 100% sure. Also sorry for the late response

1 Like

Yeah, there are 2 module scripts I made for KeybindModule and LoadoutModule, but I think that I made the LoadoutModule first. When I finish the script, It seems to be working. But when I made the KeybindModule, I think it damages the script

EDIT: Maybe I can try to merge these 2 module scripts together, and I think that it will seems to be working

Could be the cause perhaps, not to sure since I don’t have a lot of info on the issue sorry that I couldn’t be of an assistants but I would recommend merging it.

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