I need help with value loading data store?
Asked by
8 years ago Edited 8 years ago
Well I have a datastore setup the issue is when I print out the health value it comes out as 50 not 100 and the saves isn't working when I changed the value. So like if I join in the game again when I changed the value it will come out as 50 so that means if it came out as 0 it should of been 100 not 50...
Code:
05 | local Data = game:GetService( "DataStoreService" ) |
06 | local HungerValue = Data:GetDataStore( "8432345EKF" ) |
07 | local ThirstValue = Data:GetDataStore( "83924355KJ" ) |
08 | local HealthValue = Data:GetDataStore( "38533456KD" ) |
10 | pls = game.Players:GetUserIdFromNameAsync(name) |
11 | print (HealthValue:GetAsync(pls)) |
12 | game.Players.PlayerAdded:connect( function (plr) |
14 | local folder = Instance.new( "Folder" , plr) |
15 | local hunger = Instance.new( "IntValue" , folder) |
16 | local thirst = Instance.new( "IntValue" , folder) |
17 | local health = Instance.new( "IntValue" , folder) |
19 | hunger.Name = "Hunger" |
20 | thirst.Name = "Thirst" |
21 | health.Name = "Health" |
22 | hunger.Value = HungerValue:GetAsync(plr.userId) or 100 |
23 | thirst.Value = ThirstValue:GetAsync(plr.userId) or 100 |
24 | health.Value = HealthValue:GetAsync(plr.userId) or 100 |
26 | game.Players.PlayerRemoving:connect( function (plr) |
27 | local stat = plr.Stats |
28 | HungerValue:SetAsync(plr.userId, stat.Hunger.Value) |
29 | ThirstValue:SetAsync(plr.userId, stat.Thirst.Value) |
30 | HealthValue:SetAsync(plr.userId, stat.Health.Value) |