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 do I make a script to save values?

Previous Thread :: Next Thread 
RockerCaleb1234 is not online. RockerCaleb1234
Joined: 06 Jun 2012
Total Posts: 26
07 Feb 2016 07:26 AM
I have tried data store, data persistence, using JSON, and simply looking in free models yet can't seem to find a way to make the value save. Help?



RockerCaleb1234 ;P
Report Abuse
xlaser23 is not online. xlaser23
Joined: 10 Dec 2011
Total Posts: 20341
07 Feb 2016 07:28 AM
my example datastores use it



local DataStore = game:GetService("DataStoreService"):GetDataStore("LaserStore")


game.Players.PlayerAdded:connect(function(player)

local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"

local points = Instance.new("IntValue", stats)
points.Name = "Points"

local coins = Instance.new("IntValue", stats)
coins.Name = "Coins"

local key = "player-"..player.userId

local savedValues = DataStore:GetAsync(key)

if savedValues then
--Save format: {points, coins}
points.Value = savedValues[1]
coins.Value = savedValues[2]
else
local valuesToSave = {points.Value, coins.Value}
DataStore:SetAsync(key, valuesToSave)
end

end)


--[[ local DataStore = game:GetService("DataStoreService")<---This Part Gets the Service
"DataStore:GetDataStore("Anyname")<---This is the Datastore u get the data from


game.Players.PlayerAdded:connect(function(player)<---Player Added

local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"

local points = Instance.new("IntValue", stats)
points.Name = "Points"

local coins = Instance.new("IntValue", stats)
coins.Name = "Coins"-- Making Leader Board stats



<----Things gonna get Real---->

i will do this (-1-) to show the Order in the teaching





local key = "player-"..player.userId(-2-)The key is the code for the Saved Data Every Player needs a special code so use player.userId
because every player has there own userID

local savedValues = DataStore:GetAsync(key)(-1-)This Getting the Data from the Key

if savedValues then(-3-)Checking if people have the data if it does then
--Save format: {points, coins}<--Table Showing how the saving is gonna work out
points.Value = savedValues[1]<--This numbers show the Order in which the table is going to save/load in
coins.Value = savedValues[2]
else
local valuesToSave = {points.Value, coins.Value}<---Saves Points
DataStore:SetAsync(key, valuesToSave)<---Setting the data in the datastores
end


--]]




http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$131 Tx559 (づ ゚ ³ ゚)づ
Report Abuse
RockerCaleb1234 is not online. RockerCaleb1234
Joined: 06 Jun 2012
Total Posts: 26
07 Feb 2016 08:15 AM
Still doesn't work



RockerCaleb1234 ;P
Report Abuse
xlaser23 is not online. xlaser23
Joined: 10 Dec 2011
Total Posts: 20341
07 Feb 2016 08:18 AM
this works perfectly fine

ur doing something wrong



http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$131 Tx559 (づ ゚ ³ ゚)づ
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