I have two separate scripts going on here. The Level and XP gets saved fine, but the Gold and CCode don't. I don't know if its because the two scripts are conflicting with each other or what??
The final objective is to have a leaderboard that saves Level, gold, xp and CCode so when I go between places in my 'universe' it keeps the data.
local Data = game:GetService("DataStoreService")
local CashStore = Data:GetDataStore("cash")
local LevelStore = Data:GetDataStore("clicks")
local XPStore = Data:GetDataStore("clicks2")
local StrStore = Data:GetDataStore("clicks4")
local ConStore = Data:GetDataStore("clicks5")
local IntStore = Data:GetDataStore("clicks6")
local DexStore = Data:GetDataStore("clicks7")
local CCStore = Data:GetDataStore("clicks9")
function onXPChanged(player, XP, level)
if XP.Value>= 100*(level.Value) and level.Value < script.LevelCap.Value then
XP.Value = XP.Value - (level.Value*100)
level.Value = level.Value + 1
end
end
function onLevelUp(player, XP, level)
if player.Character~=nil then
for i = 1,5 do
local fireworks = Instance.new("Part")
fireworks.Shape = 0
fireworks.formFactor = "Symmetric"
fireworks.Size = Vector3.new(1,1,1)
fireworks.BrickColor = BrickColor.Random()
fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
fireworks.Parent = game.Workspace
game:GetService("Debris"):AddItem(fireworks, 2)
fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
end
end
local m = Instance.new("Hint")
m.Parent = game.Workspace
m.Text = player.Name .. " has gained a level!"
wait(5)
m.Parent = nil
end
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local attrb = Instance.new("IntValue")
attrb.Name = "attributes"
local clicks = Instance.new("IntValue")
clicks.Name = "Lvl"
clicks.Value = 0
local stats2 = Instance.new("IntValue")
stats2.Name = "Quest"
stats2.Parent = newPlayer
local clicks2 = Instance.new("IntValue")
clicks2.Name = "XP"
clicks2.Value = 0
local cash = Instance.new("IntValue")
cash.Name = "Gold"
cash.Value = 0
local clicks4 = Instance.new("IntValue")
clicks4.Name = "Strength"
clicks4.Value = 0
local clicks5 = Instance.new("IntValue")
clicks5.Name = "Constitution"
clicks5.Value = 0
local clicks6 = Instance.new("IntValue")
clicks6.Name = "Intelligence"
clicks6.Value = 0
local clicks7 = Instance.new("IntValue")
clicks7.Name = "Dexterity"
clicks7.Value = 0
local clicks8 = Instance.new("IntValue")
clicks8.Name = "points"
clicks8.Value = 0
local clicks9 = Instance.new("IntValue")
clicks9.Name = "CCode"
clicks9.Value = 0
clicks.Parent = stats
clicks2.Parent = stats
cash.Parent = stats
clicks4.Parent = attrb
clicks5.Parent = attrb
clicks6.Parent = attrb
clicks7.Parent = attrb
clicks8.Parent = attrb
clicks9.Parent = stats
stats.Parent = newPlayer
attrb.Parent = newPlayer
clicks2.Changed:connect(function() onXPChanged(newPlayer, clicks2, clicks) end)
clicks.Changed:connect(function() onLevelUp(newPlayer, clicks2, clicks) end)
if LevelStore:GetAsync("Points_"..newPlayer.Name) ~= nil then
clicks.Value = LevelStore:GetAsync("Points_"..newPlayer.Name)
else
clicks.Value = 1
end
clicks.Changed:connect(function(Val)
LevelStore:SetAsync("Points_"..newPlayer.Name, Val)
end)
if XPStore:GetAsync("Points_"..newPlayer.Name) ~= nil then
clicks2.Value = XPStore:GetAsync("Points_"..newPlayer.Name)
else
clicks2.Value = 0
end
clicks2.Changed:connect(function(Val)
XPStore:SetAsync("Points_"..newPlayer.Name, Val)
end)
if StrStore:GetAsync("Points_"..newPlayer.Name) ~= nil then
clicks4.Value = StrStore:GetAsync("Points_"..newPlayer.Name)
else
clicks4.Value = 0
end
clicks4.Changed:connect(function(Val)
StrStore:SetAsync("Points_"..newPlayer.Name, Val)
end)
if ConStore:GetAsync("Points_"..newPlayer.Name) ~= nil then
clicks5.Value = ConStore:GetAsync("Points_"..newPlayer.Name)
else
clicks5.Value = 0
end
clicks5.Changed:connect(function(Val)
ConStore:SetAsync("Points_"..newPlayer.Name, Val)
end)
if IntStore:GetAsync("Points_"..newPlayer.Name) ~= nil then
clicks6.Value = IntStore:GetAsync("Points_"..newPlayer.Name)
else
clicks6.Value = 0
end
clicks6.Changed:connect(function(Val)
IntStore:SetAsync("Points_"..newPlayer.Name, Val)
end)
if DexStore:GetAsync("Points_"..newPlayer.Name) ~= nil then
clicks7.Value = DexStore:GetAsync("Points_"..newPlayer.Name)
else
clicks7.Value = 0
end
clicks7.Changed:connect(function(Val)
DexStore:SetAsync("Points_"..newPlayer.Name, Val)
end)
if CCStore:GetAsync("Points_"..newPlayer.Name) ~= nil then
clicks9.Value = CCStore:GetAsync("Points_"..newPlayer.Name)
else
clicks9.Value = 0
end
clicks9.Changed:connect(function(Val)
CCStore:SetAsync("Points_"..newPlayer.Name, Val)
end)
newPlayer.CharacterAdded:connect(function(c)
c.Humanoid.MaxHealth = newPlayer.leaderstats.Lvl.Value * 10 + 100
c.Humanoid.Health = newPlayer.leaderstats.Lvl.Value * 10 + 100
end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)
Script 2
--[Savaing]--
game.Players.PlayerRemoving:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
print("saved data number "..i)
end
print("Stats successfully saved")
end)
--[Loading]--
game.Players.PlayerAdded:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
player:WaitForChild("leaderstats")
wait(1)
local stats = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
print("stat numba "..i.." has been found")
end
end)
