I'm pretty new to DataStorage, but I think that it's time that I move my game from DataPersistance to DataStorage. The only problem is that my DataPersistance code also has the level up code inside of it. Can someone convert this for me? (ik that this isnt a request site, so if I'm breaking any rules please notify me and I will mark this as solved)
function onXPChanged(player, XP, level)
if XP.Value>=level.Value * 20 then
XP.Value = XP.Value - level.Value * 20
level.Value = level.Value + 1
player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + 10
player.Character.Humanoid.Health = player.Character.Humanoid.Health + 10
player.Levelss.FAP.Value = player.Levelss.FAP.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.Material = "Neon"
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
local fu = Instance.new("Fire")
fu.Size = 5
fu.Heat = 5
fu.Color = Color3.new(math.random(),math.random(),math.random())
fu.SecondaryColor = Color3.new(math.random(), math.random(), math.random())
fu.Parent = fireworks
game:GetService("Debris"):AddItem(fireworks, 2)
fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
end
end
end
function saveScore(player, score)
player:SaveNumber("Level", score)
end
function saveScore2(player, score)
player:SaveNumber("XP", score)
end
function saveScore3 (player, score)
player:SaveNumber("FAP", score)
end
function saveScore4 (player, score)
player:SaveNumber("RandomMove", score)
end
function saveScore5 (player, score)
player:SaveNumber("Muny", score)
end
function saveScore6 (player, score)
player:SaveNumber("RangedPunch", score)
end
function loadScore(player, clickCounter)
local score = player:LoadNumber("Level")
if score ~= 1 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore2(player, clickCounter)
local score = player:LoadNumber("XP")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore3(player, clickCounter)
local score = player:LoadNumber("FAP")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore4(player, clickCounter)
local score = player:LoadNumber("RandomMove")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore5(player, clickCounter)
local score = player:LoadNumber("Muny")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore6(player, clickCounter)
local score = player:LoadNumber("RangedPunch")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "Levelss"
local clicks = Instance.new("IntValue")
clicks.Name = "Level"
clicks.Value = 1
local clicks2 = Instance.new("IntValue")
clicks2.Name = "XP"
clicks2.Value = 0
local clicks3 = Instance.new("IntValue")
clicks3.Name = "FAP"
clicks3.Value = 1
local clicks4 = Instance.new("IntValue")
clicks4.Name = "RandomMove"
clicks4.Value = 0
local clicks5 = Instance.new("IntValue")
clicks5.Name = "Muny"
clicks5.Value = 250
local clicks6 = Instance.new("IntValue")
clicks6.Name = "RangedPunch"
clicks6.Value = 0
clicks.Parent = stats
clicks2.Parent = stats
clicks3.Parent = stats
clicks4.Parent = stats
clicks5.Parent = stats
clicks6.Parent = stats
stats.Parent = newPlayer
clicks2.Changed:connect(function() onXPChanged(newPlayer, clicks2, clicks) end)
clicks.Changed:connect(function() onLevelUp(newPlayer, clicks2, clicks) end)
newPlayer:WaitForDataReady()
loadScore(newPlayer, clicks)
loadScore2(newPlayer, clicks2)
loadScore3(newPlayer, clicks3)
loadScore4(newPlayer, clicks4)
loadScore5(newPlayer, clicks5)
loadScore6(newPlayer, clicks6)
newPlayer.CharacterAdded:connect(function(c)
c.Humanoid.MaxHealth = newPlayer.Levelss.Level.Value * 10 + 100
c.Humanoid.Health = newPlayer.Levelss.Level.Value * 10 + 100
end)
end
function onPlayerRemoving(player)
print("Attempting to save score for " .. player.Name)
local stats = player:FindFirstChild("Levelss")
if (stats ~= nil) then
local clicks = stats:FindFirstChild("Level")
local clicks2 = stats:FindFirstChild("XP")
local clicks3 = stats:FindFirstChild("FAP")
local clicks4 = stats:FindFirstChild("RandomMove")
local clicks5 = stats:FindFirstChild("Muny")
local clicks6 = stats:FindFirstChild("RangedPunch")
if (clicks ~= nil)and(clicks2 ~= nil)and(clicks3 ~= nil)and(clicks4 ~=nil)and(clicks5 ~=nil) then
saveScore(player, clicks.Value)
saveScore2(player, clicks2.Value)
saveScore3(player, clicks3.Value)
saveScore4(player, clicks4.Value)
saveScore5(player, clicks5.Value)
saveScore6(player, clicks6.Value)
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerRemoving)

1 comment
http://wiki.roblox.com/index.php?title=Writing_Clean_Code#Indenting