Unable to assign property value, string expected, got nil

Whenever i try to load the player’s ability, i keep getting this error, i created a testing data store to check if this would fix the issue but it didn’t help.

	local Ability = Instance.new("StringValue")
	Ability.Name = "Ability"
	Ability.Value = "None"
	Ability.Parent = leaderstats
	--- DataStore Stuff ---
	local Player_UserId = "User_"..Player.UserId
	local My_Data
	local My_SettingsData
	local Success, Error_Message = pcall(function()
		My_Data = MyUser_Data:GetAsync(Player_UserId)
		My_SettingsData = MyUser_Data:GetAsync(Player_UserId)
	if Success then
		if My_Data then
			Total_Kills.Value = My_Data.Total_Kills
			Deaths.Value = My_Data.Deaths
			Ability.Value = My_Data.Ability

I would appreciate it if anyone told me a solution for this issue.

Is the data correctly saved? Specifically the ability of the player? The code you provided should work under those ideal conditions.


Could you provide us the code where you save to the DataStore? That will help us find errors.

Edit: It would be more ideal if you could provide the entire script instead of just a portion of it.

	--- DataStore Stuff ---
	local Player_UserId = "User_"..Player.UserId
	local My_StatsData = {
		Total_Kills = Player:WaitForChild("leaderstats")["Total Kills"].Value;
		Deaths = Player:WaitForChild("leaderstats").Deaths.Value;
		Ability = Player:WaitForChild("leaderstats").Ability.Value;
		KillSound_ID = Player:WaitForChild("Settings").KillSound_ID.Value;
	local Success, Error_Message = pcall(function()
		MyUser_Data:SetAsync(Player_UserId, My_StatsData)
	if Success then
		print("Successfully saved "..Player.Name.."'s data.")
		error("An error occured while saving "..Player.Name.."'s data. "..Error_Message)

Are any errors/warns appearing in the developer console? Also, if you’re trying to use this from Studio, have you enabled Enable Studio Access to API Services under the Security tab in Game Settings?

Everything you’re telling me to do were already done before i started scripting this datastore.

I had to make sure because the script itself looks fine. If that’s the case, it seems some of your data is saving as nil, or your script is failing to retrieve the data. I’d recommend using print to debug whether it’s nil before saving and after the save is loaded. This way, you may identify the point at which it is failing.

I FIXED IT!!! I fixed the issue by just using a NumberValue for the ability.

1 Like

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