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
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Guys i made a datastore script

Previous Thread :: Next Thread 
Keruro is not online. 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 is not online. 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
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
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
Born2Script is not online. Born2Script
Joined: 23 Jul 2013
Total Posts: 2670
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 is not online. 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 is not online. Keruro
Joined: 23 Nov 2013
Total Posts: 2327
14 Jun 2015 04:55 PM
Rite?
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
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
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
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 is not online. 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 is not online. 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
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
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
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
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
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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