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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 17 Aug 2017 |
| Total Posts: 356 |
|
| |
|
Jetskiis
|
  |
| Joined: 17 Aug 2017 |
| Total Posts: 356 |
|
| |
|
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
|
  |
| Joined: 17 Aug 2017 |
| Total Posts: 356 |
|
| |
|
Jetskiis
|
  |
| Joined: 17 Aug 2017 |
| Total Posts: 356 |
|
| |
|
Jetskiis
|
  |
| Joined: 17 Aug 2017 |
| Total Posts: 356 |
|
| |
|
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
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 03 Dec 2017 12:09 PM |
Put that in a server script in ServerScriptService
|
|
|
| Report Abuse |
|
|