generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Data Persistence e.e

Previous Thread :: Next Thread 
GRAPHICED is not online. GRAPHICED
Joined: 01 Apr 2013
Total Posts: 136
21 Aug 2013 05:01 AM
local LevelCap = 20

levelup = function(Player, Level, XP)
if XP.Value>= 100*(Level.Value) and Level.Value < LevelCap then
XP.Value = XP.Value - (Level.Value*100)
Level.Value = Level.Value + 1
end
end

loadstats = function(Player)
local score = Player.leader:GetChildren()
for i = 1, #score do
print("Success Load")
Player:LoadNumber(score[i].Value) --score[i].Name
end
end

game:GetService("Players").PlayerAdded:connect(function(Player)

local Stats = Instance.new("IntValue",Player)
Stats.Name = "leader"
local Money = Instance.new("IntValue",Stats)
Money.Name = "Gold"
Money.Value = 500
local Level = Instance.new("IntValue",Stats)
Level.Name = "Level"
Level.Value = 1
local Walk = Instance.new("IntValue",Stats)
Walk.Name = "Walkspeed"
Walk.Value = 16
local Armor = Instance.new("IntValue",Stats)
Armor.Name = "Armor"
Armor.Value = 0
local XP = Instance.new("IntValue",Stats)
XP.Name = "XP"
XP.Value = 0

Player:WaitForDataReady()
XP.Changed:connect(function() levelup(Player, Level, XP) end)
loadstats(Player)
end)

game:GetService("Players").PlayerRemoving:connect(function(Player)
if Player.DataReady then
local score = Player.leader:GetChildren()
for i = 1, #score do
print("Success Save")
Player:SaveNumber(score[i].Value)
end
end
end)
Report Abuse
Desperian is not online. Desperian
Joined: 07 Feb 2012
Total Posts: 3371
21 Aug 2013 05:15 AM
1) The ':SaveNumber()' method takes two parameters. A key (What it will be saved as), and the value you're attempting to save. Not just a value.
2) The ':LoadNumber()' method takes a key as a parameter. If nothing is saved under the given key, it will just be blank, 0, etc.

The two main pointers.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
21 Aug 2013 05:20 AM
for i, v in pairs (Player:children()) do
if v:IsA("IntValue") and v.Name == "" then --PUT THE NAME OF DA VALUE U WANT TO LOAD
Player:LoadNumber(v.Value)
end
end


This replaces ur getxhildren thing
Report Abuse
GRAPHICED is not online. GRAPHICED
Joined: 01 Apr 2013
Total Posts: 136
21 Aug 2013 05:22 AM
Well the load works, since it changes Level to 2, but the save doesn't seem to be working.



_G['LevelCap'] = 20

levelup = function(Player, Level, XP)
if XP.Value>= 100*(Level.Value) and Level.Value < _G['LevelCap'] then
XP.Value = XP.Value - (Level.Value*100)
Level.Value = Level.Value + 1
end
end

loadstats = function(Player)
local score = Player.leader:GetChildren()
for i = 1, #score do
Player.leader.Level.Value = 2
Player:LoadNumber(score[i].Value) --score[i].Name
end
end

game:GetService("Players").PlayerAdded:connect(function(Player)

local Stats = Instance.new("IntValue",Player)
Stats.Name = "leader"
local Money = Instance.new("IntValue",Stats)
Money.Name = "Gold"
Money.Value = 500
local Level = Instance.new("IntValue",Stats)
Level.Name = "Level"
Level.Value = 1
local Walk = Instance.new("IntValue",Stats)
Walk.Name = "Walkspeed"
Walk.Value = 16
local Armor = Instance.new("IntValue",Stats)
Armor.Name = "Armor"
Armor.Value = 0
local XP = Instance.new("IntValue",Stats)
XP.Name = "XP"
XP.Value = 0

Player:WaitForDataReady()
XP.Changed:connect(function() levelup(Player, Level, XP) end)
loadstats(Player)
end)

game:GetService("Players").PlayerRemoving:connect(function(Player)
if Player.DataReady then
local score = Player.leader:GetChildren()
for i = 1, #score do
print("Success Save")
Player:SaveNumber(score[i].Name,score[i].Value)
end
end
end)
Report Abuse
Desperian is not online. Desperian
Joined: 07 Feb 2012
Total Posts: 3371
21 Aug 2013 05:29 AM
Eh, I wouldn't use the 'PlayerRemoving' event if I was you. It has been known to not actually save usually.

"There have been multiple occurrences where using this method intertwined with a PlayerRemoving event will cause the issue of it not functioning correctly. It is advised that, after correctly debugging your script, you make the attempt to make an alternative saving method, such as using the Changed event to detect value changes."
Report Abuse
GRAPHICED is not online. GRAPHICED
Joined: 01 Apr 2013
Total Posts: 136
21 Aug 2013 05:39 AM
_G['LevelCap'] = 20

levelup = function(Player, Level, XP)
if XP.Value>= 100*(Level.Value) and Level.Value < _G['LevelCap'] then
XP.Value = XP.Value - (Level.Value*100)
Level.Value = Level.Value + 1
end
end

loadstats = function(Player)
for i, v in pairs (Player.leader:children()) do
if v:IsA("IntValue") then
Player:LoadNumber(v.Name)
end
end
end

savestats = function(Player)
for i, v in pairs (Player.leader:children()) do
if v:IsA("IntValue") then
Player:SaveNumber(v.Name,v.Value)
end
end
end

game:GetService("Players").PlayerAdded:connect(function(Player)

local Stats = Instance.new("IntValue",Player)
Stats.Name = "leader"
local Money = Instance.new("IntValue",Stats)
Money.Name = "Gold"
Money.Value = 500
local Level = Instance.new("IntValue",Stats)
Level.Name = "Level"
Level.Value = 1
local Walk = Instance.new("IntValue",Stats)
Walk.Name = "Walkspeed"
Walk.Value = 16
local Armor = Instance.new("IntValue",Stats)
Armor.Name = "Armor"
Armor.Value = 0
local XP = Instance.new("IntValue",Stats)
XP.Name = "XP"
XP.Value = 0

Player:WaitForDataReady()
XP.Changed:connect(function() levelup(Player, Level, XP) end)
XP.Changed:connect(function() savestats(Player) end)
loadstats(Player)
end)
Report Abuse
GRAPHICED is not online. GRAPHICED
Joined: 01 Apr 2013
Total Posts: 136
21 Aug 2013 05:46 AM
Nevermind.
Fixed.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image