Unable to assign property Value. string expected, got nil

Idk what is going on here, can some explain?



local datastoreservice = game:GetService("DataStoreService")
local mystore = datastoreservice:GetDataStore("mydatastore")

game.Players.PlayerAdded:Connect(function(player)
	
	local OtherStuff = Instance.new("Folder",player)
	OtherStuff.Name = "OtherStuff"

	local rebirths = Instance.new("StringValue",OtherStuff)
	rebirths.Name = "rebirths"
	rebirths.Value = 1

	local rebirthcost = Instance.new("StringValue",OtherStuff)
	rebirthcost.Name = "rebirthcost"
	rebirthcost.Value = 100
	

	local playerid = "Player_" .. player.UserId
	local data = mystore:GetAsync(playerid)

	if data then
		rebirths.Value = data['rebirths']
		rebirthcost.Value = data['rebirthcost']
	else
		rebirths.Value = 10
		rebirthcost.Value = 100
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	local datatobesaved = {
		rebirths = player.OtherStuff.rebirths.Value;
		rebirthcost = player.OtherStuff.rebirthcost.Value;

	}
	local playerid = "Player_" .. player.UserId
	local success, err = pcall(function()
		mystore:SetAsync(playerid,datatobesaved)
	end)
	if success then
		print("data saved!")
	else
		print("data faield to save!")
	end
end)

line 24 btw

Yeah I’ve had this problem before aswell when I used to use datastoreservice without profileservice with multiple things to save, if you’;re doing it on studio it will error. Try doing it on the actual game by publishing it. If that doesn’t work either add a task.wait(3) at the beginning of the playeradded event.
Aye so which one worked?

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