|
| 09 Jul 2014 04:13 PM |
Hello I am working on a DBZ Game from scratch (I am new to coding, atleast in LUA), I am currently doing the save/load first, but evertime I try to use a data store or data persistance, it never works, atleast is not functional, so I ask if anyone could help me on this. (tried a tutorial on roblox wiki and on here), I am trying to save the stats of this
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model", player) leaderstats.Name = "leaderstats" local Ki = Instance.new("IntValue", leaderstats) Ki.Name = "Ki" Ki.Value = 0 end)
while wait(10) do for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("leaderstats") then Player.leaderstats.Ki.Value = Player.leaderstats.Ki.Value +5 end end end |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 04:21 PM |
| http://www.roblox.com/Global-DataStore-item?id=151263580 |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 04:40 PM |
Dueling, the saving or loading does not work, all I changed was for it to work with the leaderboard I already have, so is there anything wrong here?
--Created by Duelingwarlord, I made this just to try out datastore. If you have any confusion whatsoever, PM me.
local ds = game:GetService("DataStoreService"):GetGlobalDataStore("Stats")
stats = {["Ki"] = "NumberValue:10",["Physical"] = "NumberValue:10",["Agility"] = "NumberValue:10"} --[[Follow the sequence, specify the name of the stat and the type(NumberValue, StringValue) after make a colon with the stat you want as DEFAULT if the stat does not load Example: ["Lvl"] = "StringValue:Hi" ]]
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model", player) leaderstats.Name = "leaderstats" local key = tostring(player.userId) for k,v in pairs(stats) do local stat = Instance.new(v:sub(1,(string.indexOf(v,":") - 1))) stat.Name = k stat.Value = ds:GetAsync(key .. k) ~= nil and ds:GetAsync(key .. k) or ds:GetAsync(key .. k) == nil and v:sub((string.indexOf(v,":") + 1)) --Checks to see if there is already a value ready for the player, if not it sets the default value if not ds:GetAsync(key .. k) then ds:SetAsync((key .. k), stat.Value) end --Creates the stat in the actual datastore if it is not present stat.Parent = leaderstats--You can add if statements to set the parents Example: if (k == "Gold" or if stat.Name == "Gold") then stat.Parent = player:WaitForChild("leaderstats") end or w/e end end)
function returnValue(value) return value * 1 end
game.Players.PlayerRemoving:connect(function(player) local key = tostring(player.userId) for k,v in pairs(stats) do ds:UpdateAsync((key .. k), function() return player:findFirstChild(k).Value end) --Second argument is a function for UpdateAsync end end)
--String library to get the current index string = { indexOf = function(str,char) local index = 1 for i = 1,str:len(),1 do if str:sub(i,i):find(char) then return index end index = index + 1 end end, } |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 04:57 PM |
game.Players.PlayerRemoving:connect(function(player) local key = tostring(player.userId) for k,v in pairs(stats) do ds:UpdateAsync((key .. k), function() return player.leaderstats:findFirstChild(k).Value end) --Second argument is a function for UpdateAsync end end)
You needed to add .leaderstats in order to save.
|
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 09 Jul 2014 05:19 PM |
That model is not very helpful for learning.
It didn't help me at all. |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 09 Jul 2014 05:20 PM |
It's good, but I just found it too confusing.
GetAsync SetAsync
Are all you need really |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 05:22 PM |
| It works for ki and physicial, but not agility, agility still does not save, any fix for this? |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 05:43 PM |
I made that while learning Datastore. I can possibly update it. |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 05:45 PM |
| Okay, I got the ki and physical working so it is working, just seems it does not support 3 stats or something XD |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 08:50 PM |
| It actually does since it works for me in my version. |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 08:56 PM |
Odd, it does not for my 3 stats. care if you can see if there is anything wrong?
codes posted a few lines back. |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 09:00 PM |
| I am going to see if I can recode it XD |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2014 09:20 PM |
| I'll check it out tomorrow and will post. |
|
|
| Report Abuse |
|
|