Problem: So this is my first time really making a datastore so I am unsure as I go with the scripting process. I was wondering what I am doing wrong/if I am doing it inefficiently because in line 56 it just says "stack end". It does not continue the code any further. Any tips/help?
code:
local store = game:GetService("DataStoreService"):GetDataStore("PlayerData")
game.Players.PlayerAdded:connect(function(plr)
local fold = Instance.new("Folder")
fold.Parent = plr
fold.Name = "leaderstats1"
fold.Parent = plr
local xp = Instance.new("IntValue")
xp.Name = "Experience"
xp.Parent = fold
local maxexp = Instance.new("IntValue")
maxexp.Name = "MaxExp"
maxexp.Parent = fold
local level = Instance.new("IntValue")
level.Name = "Level"
level.Parent = fold
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = fold
local gems = Instance.new("IntValue")
gems.Name = "Gems"
gems.Parent = fold
local tries = Instance.new("IntValue")
tries.Name = "Tries"
tries.Parent = fold
local votes = Instance.new("IntValue")
votes.Name = "Votes"
votes.Parent = fold
local mana = Instance.new("IntValue")
mana.Name = "Mana"
mana.Parent = fold
local maxmana = Instance.new("IntValue")
maxmana.Name = "MaxMana"
maxmana.Parent = fold
local swordskill = Instance.new("StringValue")
swordskill.Name = "SwordSkill"
swordskill.Parent = fold
local power = Instance.new("StringValue")
power.Name = "Power"
power.Parent = fold
local third = Instance.new("StringValue")
third.Name = "Third"
third.Parent = fold
local owner = Instance.new("BoolValue")
owner.Name = "Owner"
owner.Parent = fold
local newplayer = Instance.new("BoolValue")
newplayer.Name = "NewPlayer"
newplayer.Parent = fold
local category = Instance.new("StringValue")
category.Name = "Category"
category.Parent = fold
print("Made the values")
local key = "user-"..plr.Name
print("Made user variable")
local items = store:GetAsync(key)
print("Preparing")
if items then
xp.Value = items[1]
maxexp.Value = items[2]
level.Value = items[3]
cash.Value = items[4]
gems.Value = items[5]
tries.Value = items[6]
votes.Value = items[7]
mana.Value = items[8]
maxmana.Value = items[9]
swordskill.Value = items[10]
power.Value = items[11]
third.Value = items[12]
owner.Value = items[13]
newplayer.Value = items[14]
category.Value = items[15]
print("Loaded")
else
local values = {
xp.Value,
maxexp.Value,
level.Value,
cash.Value,
gems.Value,
tries.Value,
votes.Value,
mana.Value,
maxmana.Value,
swordskill.Value,
power.Value,
third.Value,
owner.Value,
newplayer.Value,
category.Value,
}
store:SetAsync(key, values)
print("Had to make new ones")
end
if level.Value == 1 or level.Value == 0 then
if xp.Value == 1 or xp.Value == 0 then
if swordskill.Value == "" then
if power.Value == "" then
if third.Value == "" then
plr:WaitForChild("leaderstats1").tries.Value = plr:WaitForChild("leaderstats1").tries.Value + 10
newplayer.Value = true
if tries.Value > 400 then
tries.Value = 400
print("Was new player")
end
end
end
end
end
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local values = {
plr.leaderstats1.xp.Value,
plr.leaderstats1.maxexp.Value,
plr.leaderstats1.level.Value,
plr.leaderstats1.cash.Value,
plr.leaderstats1.gems.Value,
plr.leaderstats1.tries.Value,
plr.leaderstats1.votes.Value,
plr.leaderstats1.mana.Value,
plr.leaderstats1.maxmana.Value,
plr.leaderstats1.swordskill.Value,
plr.leaderstats1.power.Value,
plr.leaderstats1.third.Value,
plr.leaderstats1.owner.Value,
plr.leaderstats1.newplayer.Value,
plr.leaderstats1.category.Value,
}
local key = "user-"..plr.Name
store:SetAsync(key, values)
print("Did it")
end)

3 comments
Why you have the players removing function in the player added function?
Because I put too may lines before the remove event so I thought that I ended the first event before putting the next one. Fixed it :P
This data will not be saving as you have not accessed the correct name, e.g you have xp when it should be Experience as that is the objects name.