ServerScriptService.datastore:42: attempt to index nil with 'Money' - Server

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? A working datastore.

  2. What is the issue? ServerScriptService.datastore:42: attempt to index nil with ‘Money’ - Server

  3. What solutions have you tried so far? Tried to fix it myself

local Data = game:GetService("DataStoreService"):GetDataStore("Currencies")

game.Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder", game.ServerStorage.ds)
	Folder.Name = plr.Name
	local money = Instance.new("NumberValue", Folder)
	money.Name = 'Money'
	local wins = Instance.new("NumberValue", Folder)
	wins.Name = "Wins"
	local hasBloody = Instance.new("BoolValue", Folder)
	hasBloody.Name = "Bloody"
	local hasPencil = Instance.new("BoolValue", Folder)
	hasPencil.Name = "Pencil"
	local hasRainbow = Instance.new("BoolValue", Folder)
	hasRainbow.Name = "Rainbow"
	local hasNoob = Instance.new("BoolValue", Folder)
	hasNoob.Name = "Noob"

	local saveditems = Data:GetAsync(plr.userId)

	if saveditems then
		money.Value = saveditems.Money
		wins.Value = saveditems.Wins
		hasBloody.Value = saveditems.hasBloody
		hasPencil.Value = saveditems.hasPencil
		hasRainbow.Value = saveditems.hasRainbow
		hasNoob.Value = saveditems.hasNoob
	else

		money.Value = 0 
		wins.Value = 0
		hasBloody.Value = false
		hasPencil.Value = false
		hasRainbow.Value = false
		hasNoob.Value = false
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local Saving = 
		{
			["Money"] = game.ServerStorage:FindFirstChild(plr.Name).Money.Value;
			["Wins"] = game.ServerStorage:FindFirstChild(plr.Name).Wins.Value;
			["hasNoob"] = game.ServerStorage:FindFirstChild(plr.Name).Noob.Value;
			["hasPencil"] = game.ServerStorage:FindFirstChild(plr.Name).Pencil.Value;
			["hasRainbow"] = game.ServerStorage:FindFirstChild(plr.Name).Rainbow.Value;
			["hasBloody"] = game.ServerStorage:FindFirstChild(plr.Name).Bloody.Value;
		}

	Data:SetAsync(plr.userId, Saving)
end)

What’s the exact line of code erroring?

1 Like
			["Money"] = game.ServerStorage:FindFirstChild(plr.Name).Money.Value;

When creating the player folder, you set it to ServerStorage.ds.

When removing, you only reference ServerStorage[plr.Name]

1 Like

wait im stupid, i had to type serverstorage.ds since i made a file for that, sorry for wasting your time and thanks for helping

1 Like

yeah i realized that just now, sorry man

1 Like

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