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: Data persistence

Previous Thread :: Next Thread 
000killnoobs000 is not online. 000killnoobs000
Joined: 03 Feb 2012
Total Posts: 503
29 Jul 2015 11:50 AM
Does it carry on between places in a universe?
Report Abuse
myactivetestplace is not online. myactivetestplace
Joined: 11 Jul 2015
Total Posts: 3733
29 Jul 2015 11:52 AM
good question, i asked this a while back and someone said yes :)
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
29 Jul 2015 11:54 AM
It can save itself in one game.

Data stores are much better.
Report Abuse
000killnoobs000 is not online. 000killnoobs000
Joined: 03 Feb 2012
Total Posts: 503
29 Jul 2015 12:00 PM
So how would one turn this data persistence script into a datastore?

-------------------------------------[[ SAVING ]]--------------------------------------
function saveHair(player, playerHair)
player:SaveNumber("Hair", playerHair)
end

-------------------------------------[[ LOADING ]]-------------------------------------
function loadHair(player, Hair)
local playerHair = player:LoadNumber("Hair")

if playerHair ~= 0 then
Hair.Value = playerHair
else
print("No hair to load")
end

end

-------------------------------------[[ STARTING ]]------------------------------------
function onPlayerEntered(newPlayer)


local custom = Instance.new("IntValue")
custom.Name = "Customisation"

local Hair = Instance.new("IntValue")
Hair.Name = "Hair"
Hair.Value = 0

custom.Parent = newPlayer
Hair.Parent = custom

newPlayer:WaitForDataReady()

-- try loading the player's score
loadHand(newPlayer, Hand)
loadRace(newPlayer, Race)
loadKi(newPlayer, Ki)
loadP(newPlayer, P)
loadPxp(newPlayer, Pxp)
loadPLvl(newPlayer, PLvl)
loadHair(newPlayer, Hair)
loadHairCol(newPlayer, HairCol)
loadTop(newPlayer, Top)
loadBottom(newPlayer, Bottom)
loadBuild(newPlayer, Build)
end

-------------------------------------[[ AUTOSAVE ]]------------------------------------

function onPlayerRemoving(player)
print("Attempting to save score for " .. player.Name)
local custom = player:FindFirstChild("Customisation")
if (custom ~= nil) then
local Hair = custom:FindFirstChild("Hair")
if (Hair ~= nil) then
saveHair(player, Hair.Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerRemoving)
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
29 Jul 2015 12:03 PM
DS > DP

http://www.roblox.com/Forum/ShowPost.aspx?PostID=161921763#161924571
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
29 Jul 2015 12:04 PM
http://wiki.roblox.com/index.php?title=Data_store
Report Abuse
verbalAKspray is not online. verbalAKspray
Joined: 09 Jul 2014
Total Posts: 23685
29 Jul 2015 12:04 PM
TO SAVE IT TO DATA STORE DO THE DATA SAVING STORE THING AND THERE U GO IT IS SAVED INSIDE OR ON TOP OF THE DATA STORE
Report Abuse
verbalAKspray is not online. verbalAKspray
Joined: 09 Jul 2014
Total Posts: 23685
29 Jul 2015 12:04 PM
@WAR DP FEELS BETTER THO
Report Abuse
000killnoobs000 is not online. 000killnoobs000
Joined: 03 Feb 2012
Total Posts: 503
29 Jul 2015 12:04 PM
@Geo I've already seen that, but it's too complicated e.e
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
29 Jul 2015 12:07 PM
local DS = game:GetService("DataStoreService"):GetDataStore("Hair")

-------------------------------------[[ SAVING ]]--------------------------------------
function saveHair(player, playerHair)
DS:SetAsync("Hair_"..player.userId, playerHair)
end

-------------------------------------[[ LOADING ]]-------------------------------------
function loadHair(player, Hair)
local playerHair = DS:GetAsync("Hair_"..player.userId)

if playerHair ~= nil then
Hair.Value = playerHair
else
print("No hair to load")
end

end

-------------------------------------[[ STARTING ]]------------------------------------
function onPlayerEntered(newPlayer)


local custom = Instance.new("IntValue")
custom.Name = "Customisation"

local Hair = Instance.new("IntValue")
Hair.Name = "Hair"
Hair.Value = 0

custom.Parent = newPlayer
Hair.Parent = custom

-- try loading the player's score
loadHand(newPlayer, Hand)
loadRace(newPlayer, Race)
loadKi(newPlayer, Ki)
loadP(newPlayer, P)
loadPxp(newPlayer, Pxp)
loadPLvl(newPlayer, PLvl)
loadHair(newPlayer, Hair)
loadHairCol(newPlayer, HairCol)
loadTop(newPlayer, Top)
loadBottom(newPlayer, Bottom)
loadBuild(newPlayer, Build)
end

-------------------------------------[[ AUTOSAVE ]]------------------------------------

function onPlayerRemoving(player)
print("Attempting to save score for " .. player.Name)
local custom = player:FindFirstChild("Customisation")
if (custom ~= nil) then
local Hair = custom:FindFirstChild("Hair")
if (Hair ~= nil) then
saveHair(player, Hair.Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerRemoving)













Something like that
Report Abuse
000killnoobs000 is not online. 000killnoobs000
Joined: 03 Feb 2012
Total Posts: 503
29 Jul 2015 01:32 PM
Thanks war, that's exactly how you do it :)
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
29 Jul 2015 01:34 PM
Np, glad I was able to help :D
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