You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? A working datastore.
-
What is the issue? ServerScriptService.datastore:42: attempt to index nil with ‘Money’ - Server
-
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)