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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: PCall Data Persistance

Previous Thread :: Next Thread 
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
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
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
13 Feb 2014 03:27 PM
Bump
Report Abuse
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
13 Feb 2014 03:29 PM
Bump bump...
Report Abuse
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
13 Feb 2014 03:33 PM
Bumpity bump bump...
Report Abuse
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
13 Feb 2014 03:44 PM
Bumnp...
Report Abuse
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
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 is not online. 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
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
13 Feb 2014 03:57 PM
Hm, ok. But if I have a Instance. How would I use Changed on it?
Report Abuse
DataStore is not online. DataStore
Joined: 07 Feb 2012
Total Posts: 8540
13 Feb 2014 04:08 PM
What do you mean?
Report Abuse
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
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
ninjaxrasx is not online. ninjaxrasx
Joined: 29 May 2008
Total Posts: 757
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
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