Keruro
|
  |
| Joined: 23 Nov 2013 |
| Total Posts: 2327 |
|
|
| 14 Jun 2015 04:49 PM |
I hope you like it! Also its soopr useful for games. This one is with leaderstats and cash. U know...
local creditdata = game:GetService("DataStoreService"):GetDataStore("CreditData")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "MoneyTest" cash.Parent = stats stats.Parent = player if creditdata:GetAsync(player.userId) ~= nil then cash.Value = creditdata:GetAsync(player.userId) end while true do wait(0.1) -- saving every 0.1 second :3 creditdata:SetAsync(player.userId,cash.Value) -- here ya go pal end end)
|
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 14 Jun 2015 04:50 PM |
| Run that script for a full five minutes and you'll see why you never save that often. |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2015 04:50 PM |
"while true do wait(0.1) -- saving every 0.1 second :3 creditdata:SetAsync(player.userId,cash.Value) -- here ya go pal end"
*horror music plays*
there's data limits man check the datastore article
|
|
|
| Report Abuse |
|
|
|
| 14 Jun 2015 04:52 PM |
@Cheif Does that make it so if your game become popular, no data will be stores anymore? |
|
|
| Report Abuse |
|
|
Keruro
|
  |
| Joined: 23 Nov 2013 |
| Total Posts: 2327 |
|
|
| 14 Jun 2015 04:53 PM |
Ooops my fault. But when you make like to earn money you need to put the creditdata:SetAsync(player.userId,cash.Value) |
|
|
| Report Abuse |
|
|
Keruro
|
  |
| Joined: 23 Nov 2013 |
| Total Posts: 2327 |
|
| |
|
|
| 14 Jun 2015 04:57 PM |
"@Cheif Does that make it so if your game become popular, no data will be stores anymore?"
with a wait(0.1) that thing is going to go over the buffer within seconds
it'll go into a saving queue to be saved
so basically you're wasting roughly 99% of your calls to setasync since the whole point of 0.1 is because he wants it saved constantly, and it won't even be nearly constant, so it's pointless
so the first 6 (or whatever the number is) saveasyncs will work and the rest will be outdated
this has a lot of potential problems including the saving of old, outdated data which would be very bad |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2015 04:58 PM |
@keruo
don't use loops for saving, either use PlayerRemoving or a server loop not in PlayerAdded for all players
and game.OnClose |
|
|
| Report Abuse |
|
|
Keruro
|
  |
| Joined: 23 Nov 2013 |
| Total Posts: 2327 |
|
|
| 14 Jun 2015 05:03 PM |
Ok so i get it
local creditdata = game:GetService("DataStoreService"):GetDataStore("CreditData")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "MoneyTest" cash.Parent = stats stats.Parent = player if creditdata:GetAsync(player.userId) ~= nil then cash.Value = creditdata:GetAsync(player.userId) end end)
And when i get money then i need script like this:
[Insert money adding here]
creditdata:SetAsync(player.userId,cash.Value)
right?
|
|
|
| Report Abuse |
|
|
Keruro
|
  |
| Joined: 23 Nov 2013 |
| Total Posts: 2327 |
|
|
| 14 Jun 2015 05:04 PM |
OR EVEN MORE SIMPLE JUST ADD NEW LINE
game.Players.PlayerRemoving:connect(function(player) creditdata:SetAsync(player.userId,cash.Value) end) |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2015 05:05 PM |
what i do is use a DataReady boolvalue i make at the end of playeradded, works really well and i can use it everywhere. it's great.
playeradded
if player has key in datastore, load data
else, save a key to datastore
playerremoving
if player has data ready
save to key |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2015 05:05 PM |
local creditdata = game:GetService("DataStoreService"):GetDataStore("CreditData")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "MoneyTest" cash.Parent = stats stats.Parent = player if creditdata:GetAsync(player.userId) ~= nil then cash.Value = creditdata:GetAsync(player.userId) end while true do wait(0) -- saving every 0 second :3 creditdata:SetAsync(player.userId,cash.Value) -- here ya go pal end end)
Fixed. *sunglasses* |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2015 05:06 PM |
of course the PlayerRemoving method is a tiny bit risky if for some reason people keep leaving and rejoining the server a lot
that could definitely be bad.
|
|
|
| Report Abuse |
|
|
Keruro
|
  |
| Joined: 23 Nov 2013 |
| Total Posts: 2327 |
|
|
| 14 Jun 2015 05:08 PM |
Little bit of risk = i dont give a poo becouse my game is going to be beta btw. |
|
|
| Report Abuse |
|
|
Keruro
|
  |
| Joined: 23 Nov 2013 |
| Total Posts: 2327 |
|
|
| 14 Jun 2015 05:11 PM |
And acttualy i am happy that i learned it tho. Becouse i was looking for weeks for the datastore to work |
|
|
| Report Abuse |
|
|