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

Previous Thread :: Next Thread 
ServerStorage is not online. ServerStorage
Joined: 03 Oct 2013
Total Posts: 111
19 Jan 2014 02:26 PM
-- Very bad problem but not sure why its doing it. :/

local stats = leaderstats
game.Players.PlayerRemoving:connect(function(p)
if p:findFirstChild("stats") then
p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId),p.Skills)
end end)

game.Players.PlayerAdded:connect(function(p)
wait(5)
for k = 1, 60, 0.03 do
wait()
if p:findFirstChild("stats") and p.DataReady then break end
end
local Loaded = nil
if p:findFirstChild("stats") and pcall(function() Loaded = p:LoadInstance("SavedStatPNum"..tostring(game.PlaceId)) end) then
for j, v in pairs(Loaded:GetChildren()) do
pcall(function() p.stats[v.Name].Value = v.Value end)
end end end)


--It dosen't always save...!
--about 80% it saves but other 20% it deletes all your stats :(
--and i'm not sure whats wrong with it no output.. :l
Report Abuse
ServerStorage is not online. ServerStorage
Joined: 03 Oct 2013
Total Posts: 111
19 Jan 2014 02:44 PM
BumPz
Report Abuse
ServerStorage is not online. ServerStorage
Joined: 03 Oct 2013
Total Posts: 111
19 Jan 2014 04:21 PM
well?
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
19 Jan 2014 04:23 PM
1. PlayerRemoving is unreliable, it may not finish before the player is completely gone
2. Just use a data loading function that loads the data if it's there, and creates new data if it's gone
3. Use a save GUI or an autosave feature
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
19 Jan 2014 04:23 PM
Pcall saving?
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
19 Jan 2014 04:25 PM
Protected calls are pretty neccesary for DP
The data may not always be there

Also, here's an example of mine:

main = script.Parent
gb = game:GetService("ServerStorage").GlobalResource
bin = gb.DataBin

local savebin
local score

function PlayerAdded(player)
repeat wait() until player.DataReady
local check = pcall(function() savebin = player:LoadInstance("Data") end)
if not check or savebin == nil then
print("No saved bin found, making new")
bin:clone().Parent = player
else
savebin.Parent = player
print("Data Loaded Successfully")
end

local stats = Instance.new("IntValue", player);
stats.Name = "leaderstats";
local pts = Instance.new("IntValue", stats);
pts.Name = "Drachmas";

local humanoid = player.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, player) end )
player.Changed:connect(function(property) onPlayerRespawn(property, player) end )

if not pcall(function() score = player:LoadNumber("Points") end) then
pts.Value = 0
else
pts.Value = score
end
print("Created Data for: " ..player.Name)
player.CharacterAdded:connect(function(p) Instance.new("ForceField", p) end)
end



game:GetService("Players").PlayerAdded:connect(PlayerAdded)
-----
Report Abuse
ServerStorage is not online. ServerStorage
Joined: 03 Oct 2013
Total Posts: 111
19 Jan 2014 04:46 PM
So what should i use instead of childremove?
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
19 Jan 2014 04:48 PM
It does not save till u leave, so i suggest saving then only.
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