|
| 13 Feb 2014 03:20 PM |
This is what I'm currently Using:
game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady if player.DataReady then local money if not pcall(function() money = player:LoadNumber("Money"..tostring(game.PlaceId)) end) then wait() elseif money then pcall(function() player.Money.Value = money end) end end end)
game.Players.PlayerRemoving:connect(function(playerlea) playerlea:SaveNumber("Money"..tostring(game.PlaceId),playerlea.Money.Value) end)
It seems to load and save well. But at some point it stopped saving. I tried Pcall on the save
pcall(function() playerlea:SaveNumber("Money"..tostring(game.PlaceId),playerlea.Money.Value) end)
It didn't seem to work anymore. So I'm wodering if there's a safer way to save instead of using playerlea:SaveNumber("Money"..tostring(game.PlaceId),playerlea.Money.Value)
Is there a way to do it with pcall and make it work?
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
|
| 13 Feb 2014 03:52 PM |
| Gosh, no ones answers... I could really use Cloonetrooper or CrazyMan. I know they are good. |
|
|
| Report Abuse |
|
|
DataStore
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 8540 |
|
|
| 13 Feb 2014 03:54 PM |
1) You shouldn't save when the player is leaving, it can lead to data loss and can also cause data not to save at all. 2) There is also no reason, at all, to use pcall. 3) You're missing the parenthesis for 'WaitForDataReady' - wouldn't of worked in the first place due to this 4) Don't see why you're doing something funky with PlaceId, but whatever floats your boat.
The below should work, but isn't tested.
local PlaceID = tostring(game.PlaceId)
game.Players.PlayerAdded:connect(function(Player) if Player:WaitForDataReady() then --// The method returns a boolean, which is essentially the 'DataReady' property's state. local Money = Player:LoadNumber("Money"..PlaceID) local MoneyVal = Player:WaitForChild("Money") --// Waiting for the instance. May not actually be there when it gets to here. MoneyVal.Value = Money MoneyVal.Changed:connect(function(NewValue) --// Saving the new value everytime money is changed. Player:SaveNumber("Money"..PlaceID, NewValue) end) end end) |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 03:57 PM |
| Hm, ok. But if I have a Instance. How would I use Changed on it? |
|
|
| Report Abuse |
|
|
DataStore
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 8540 |
|
| |
|
|
| 13 Feb 2014 04:29 PM |
Lets say I have a BoolValue. Inside that value it contains multiple other values. If I save the instance. I'll be saving and loading all the values inside of it when I join the game. The Bool is like a Parent to all the values. It's like grouping them together like a model.
If I was to use SaveInstance. How would I make it compatible with the Changed event without manualy identifying the vaues inside. How would I be able to fire the event if any value inside of it changes. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2014 04:30 PM |
| values* I made a typo "vaues". Also, I might be able to create a loop for this situation? Or is there a more efficient way? |
|
|
| Report Abuse |
|
|