|
| 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 |
|
|
| |
|
| |
|
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
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
| |
|
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 |
|
|
|
| 19 Jan 2014 04:46 PM |
| So what should i use instead of childremove? |
|
|
| Report Abuse |
|
|
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 |
|
|