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
 

Help needed on datastores

Previous Thread :: Next Thread 
Jetskiis is online. Jetskiis
Joined: 17 Aug 2017
Total Posts: 356
02 Dec 2017 10:59 AM
How do I merge this with a datastore so my leaderboard saves every time it changes?


game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Model")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local money = Instance.new("IntValue")
money.Name = "Kills"
money.Value = 0
money.Parent = leaderstats


local x= Instance.new("IntValue")
x.Name= "Credits"
x.Value=0
x.Parent=leaderstats

end)



Report Abuse
zackturbo52 is not online. zackturbo52
Joined: 24 May 2016
Total Posts: 63
02 Dec 2017 11:02 AM
Use UpdateAsync




For more info, check wiki below


http://wiki.roblox.com/index.php?title=Data_store
Report Abuse
1000knives is online. 1000knives
Joined: 29 Sep 2012
Total Posts: 341
02 Dec 2017 11:06 AM
money.Changed:connect(function(changedprop)
if changedprop == "Value" then
local valuestosave = money.Value
UrDataStore:SetAsync(key, valuestoave)
end
end

uh this should save the value after its changed, it will b throttled if the value changes too often


R$18,322
Report Abuse
Jetskiis is online. Jetskiis
Joined: 17 Aug 2017
Total Posts: 356
02 Dec 2017 11:41 AM
b1


Report Abuse
Jetskiis is online. Jetskiis
Joined: 17 Aug 2017
Total Posts: 356
02 Dec 2017 05:58 PM
b2


Report Abuse
LuaCymru is not online. LuaCymru
Joined: 22 Jan 2015
Total Posts: 394
02 Dec 2017 06:17 PM
I wouldn't do that, because the datastore can throttle. Save it when the player leaves the game.
Report Abuse
Jetskiis is online. Jetskiis
Joined: 17 Aug 2017
Total Posts: 356
03 Dec 2017 07:50 AM
b3


Report Abuse
Jetskiis is online. Jetskiis
Joined: 17 Aug 2017
Total Posts: 356
03 Dec 2017 10:43 AM
b4


Report Abuse
Jetskiis is online. Jetskiis
Joined: 17 Aug 2017
Total Posts: 356
03 Dec 2017 11:51 AM
bump


Report Abuse
spinywind is not online. spinywind
Joined: 26 Jan 2012
Total Posts: 3580
03 Dec 2017 12:04 PM
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Stats")

game.Players.PlayerAdded:Connect(function(Player)
local Data = DataStore:GetAsync(Player.UserId)
local Leaderstats = Player:WaitForChild("leaderstats")

if Data then
for i,v in pairs(Data) do
if Leaderstats[v[1]] then
Leaderstats[v[1].Value = v[2]
end;
end;
end;
end);

game.Players.PlayerRemoving:Connect(function(Player)
local Leaderstats = Player:WaitForChild("leaderstats")
local DataToSave = {}

for i,v in pairs(Leaderstats:GetChildren()) do
table.insert(DataToSave, {v.Name, v.Value})
end;

DataStore:UpdateAsync(Player.UserId, function(Data)
return DataToSave
end;
end);


Report Abuse
spinywind is not online. spinywind
Joined: 26 Jan 2012
Total Posts: 3580
03 Dec 2017 12:09 PM
Put that in a server script in ServerScriptService


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