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: How can I convert this into a DataStore?

Previous Thread :: Next Thread 
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
10 Apr 2015 05:51 PM
Would it be possible to take the data already on a server and transfer it over to a datastore? if this is possible..then How would I be able to convert something like this over to a DataStore?

function onPlayerEntered(player)
player:WaitForDataReady()
if player.DataReady then
if player:findFirstChild("XP") then
local xp = player:findFirstChild("XP")
local XPLoaded = player:LoadNumber(xp.Name)
if XPLoaded ~= 0 then
xp.Value = XPLoaded
end

end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("XP") then
local xp = player:findFirstChild("XP")
player:SaveNumber(xp.Name,xp.Value)
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
10 Apr 2015 05:51 PM
http://wiki.roblox.com/index.php?title=Data_store
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
10 Apr 2015 06:22 PM
local DataStoreService = game:GetService("DataStoreService")
local XPDataStore = DataStoreService:GetDataStore("XP")

Also use GetAsync and SetAsync. It shouldnt be too hard. Good luck on this!
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Apr 2015 06:33 PM
local DSS = game:GetService("DataStoreService")

function onPlayerEntered(player)
local DS = DSS:GetDataStore(player.userId)
local XPLoaded = DS:GetAsync("XP")
if not XPLoaded then
DS:SetAsync("XP", 0)
XPLoaded = 0
end
local xp = player:WaitForChild("XP")
xp.Value = XPLoaded
end

function onPlayerLeaving(player)
local DS = DSS:GetDataStore(player.userId)
local xp = player:WaitForChild("XP")
DS:SetAsync("XP",xp.Value)
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Apr 2015 06:34 PM
(I didn't test the above, I wrote it off the top of my head)
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
10 Apr 2015 06:37 PM
@OP

http://www.roblox.com/games/234837831/Datastore

There is a datastore example there.


I script -~ chimmihc
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