RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
|
| 10 Sep 2017 08:14 PM |
my old data loads but whenever i earn new levels and leave my game it doesn't save . when i come back there the same ones. the problem isn't the module script so whats wrong with this
local DataHandler = require(game.ReplicatedStorage.Modules.DataHandler) local Enl = true; local making = false
game.Players.PlayerAdded:connect(function(player) DataHandler.LoadData(player)
local Decals = {healthPoints = "rbxassetid://", Woodcutting = "rbxassetid://576876652", Strength = "rbxassetid://131559539", Attack = "rbxassetid://131559531", Defence = "rbxassetid://131559534"} local Dead = Instance.new("Sound") Dead.SoundId = ('###################################################################################################################local plrInv = player.Stats
local LevelUp = function(v) game.ReplicatedStorage.Events.LEVEL:FireClient(player, v) end
local Load = function() game.ReplicatedStorage.Events.LOAD:FireClient(player) player.Character.Humanoid.JumpPower = 0 player.Stats.Special.ForceStop.Value = false Inv =player:WaitForChild("Stats") Inv.healthPoints.health.Value = Inv.healthPoints.Level.Value Inv.healthPoints.Effect.Value = Inv.healthPoints.health.Value end Load()
GetSum = function() local total = 0 for i,v in next, Inv:GetChildren() do total = total + v.Level.Value end --player.PlayerGui.MainGui.Main.frm_skills.All.Text = 'Total Level: '..total return total end
name = function(v) Le##########end
local SoundFade = function(sound) while wait(0.075) do sound.Volume = sound.Volume - 0.01 if sound.Volume <= 0 then sound:Destroy() end end wait(5) sound:Destroy() end
player.CharacterAdded:connect(function(character) Load() player:WaitForChild("Stats").Special.ForceStop.Value = false Inv.healthPoints.health.Value = Inv.healthPoints.Level.Value plrInv.healthPoints.Effect.Value = plrInv.healthPoints.health.Value GetSum()
game.ReplicatedStorage.Events.CHARADDED:FireClient(player) end)
game.ReplicatedStorage.Events.XP:FireClient(player) end)
game.ReplicatedStorage.OX.OnServerEvent:connect(function(player, v) name(v) end)
game.Players.PlayerRemoving:connect(function(player) DataHandler.SaveData(player) end )
game.OnClose = function() for i,v in next, game.Players:GetPlayers() do DataHandler.SaveData(v) end end
|
|
|
| Report Abuse |
|
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
|
| 10 Sep 2017 08:26 PM |
| its supposed to at the end . it worked before idk what happened |
|
|
| Report Abuse |
|
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
|
| 11 Sep 2017 05:51 AM |
if ur testing in solo or testing mode then it may not work unless u have an autosave function somewhere
when u leave the game in solo mode or testing mode ur not necessarily leaving the game, so it doesnt fire such an event
also could u give us some context as to why u need the game.OnClose function? |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2017 06:08 AM |
this isn't the reason why your script doesn't work, but uhh...
OnClose is deprecated http://wiki.roblox.com/index.php?title=API:Class/DataModel/OnClose
you should be using BindToClose instead http://wiki.roblox.com/index.php?title=API:Class/DataModel/BindToClose
|
|
|
| Report Abuse |
|
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
|
| 11 Sep 2017 12:48 PM |
| Its old lol how do i use those , and im testing in game |
|
|
| Report Abuse |
|
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
|
| 11 Sep 2017 01:00 PM |
| It worked before i made the script fe |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2017 01:08 PM |
What is v that is being passed on through the RemoteEvent? What is the data type?
Table, Instance, IntValue, String??
|
|
|
| Report Abuse |
|
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
|
| 11 Sep 2017 01:20 PM |
in the module script
LoadStats = function(Player) local UserId = Player.UserId local PlayerStats = PlayerStats[UserId] for stats,data in next, PlayerStats do local NewStat = Instance.new('Folder',Player) NewStat.Name = stats for key,val in next, data do if type(val) == 'table' then local NewFolder = Instance.new('Folder',NewStat) NewFolder.Name = key for key,v in next, val do if key == 'ForceStop' then local NewVal = Instance.new('BoolValue',NewFolder) NewVal.Name = key NewVal.Value = v else local NewVal = Instance.new('IntValue',NewFolder) NewVal.Name = key NewVal.Value = v end end else local NewVal = Instance.new('IntValue',NewStat) NewVal.Name = key NewVal.Value = val end end end end
SaveStats = function(Player) local UserId = Player.UserId local Stats = Player:WaitForChild('Stats') for i,val in next, Stats:GetChildren() do if val:IsA('Folder') then for i,v in next, val:GetChildren() do PlayerStats[UserId][Stats.Name][val.Name][v.Name] = v.Value end else PlayerStats[UserId][Stats.Name][val.Name] = val.Value end end for i,v in next, PlayerStats[UserId] do for j,k in next, v do if type(k) == 'table' then for key,val in next, k do end else end end end end
DataHandler.LoadData = function(Player) local UserId = Player.UserId local Data pcall(function() Data = PlayerData:GetAsync(UserId) end) if Data then PlayerStats[UserId] = Data else local s,e = pcall(function() PlayerData:SetAsync(UserId,DefaultStats) end) if not s then warn(e) end PlayerStats[UserId] = DefaultStats end LoadStats(Player) end
DataHandler.SaveData = function(Player) local UserId = Player.UserId SaveStats(Player) local s,e = pcall(function() PlayerData:SetAsync(UserId,PlayerStats[UserId]) end) if not s then warn(e) end end return DataHandler |
|
|
| Report Abuse |
|
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
| |
|