So i make a hunger bar thrist bar and a thirst bar all IntValues in Player but when i try use this script
local DS = game:GetService("DataStoreService"):GetDataStore("SaveMyData2")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local savevalue = plr.HungerVal
local savevalue2 = plr.MedicineVal
local savevalue3 = plr.ThirstVal
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
savevalue.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
savevalue3.Value = GetSaved[3]
else
local NumbersForSaving = {savevalue.Value, savevalue2.Value, savevalue3.Value}
DS:GetAsync(plrkey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync("id_"..plr.userId, {plr.HungerVal.Value, plr.MedicineVal.Value, plr.ThirstVal.Value})
end)
And i get an error saying the HungerVal is not a valid member of Player. But when im in-game I open up Players i open Princess_Fexi007 i see there the HungerVal! How i save the IntValues so when i rejoin the game the bars are not filled up again?
This is the Bar script
local HG = script.Parent
local Text = HG:WaitForChild("Back"):WaitForChild("Text")
local Plr = game.Players.LocalPlayer
repeat wait() until Plr.Character
local Hum = Plr.Character:WaitForChild("Humanoid")
local MaxThirst = 100
local DecreaseRate = 7 -- 15 seconds = -1 hunger
local ThirstValue
if Plr:FindFirstChild("ThirstVal") then
ThirstValue = Plr.ThirstVal
ThirstValue.Value = MaxThirst
else
Instance.new("IntValue", Plr).Name = "ThirstVal"
Plr.ThirstVal.Value = MaxThirst
ThirstValue = Plr.ThirstVal
end
ThirstValue.Changed:connect(function()
Text:TweenSize(UDim2.new(ThirstValue.Value/MaxThirst,0, 1,0), "Out", "Linear", .2, true)
end)
while wait(DecreaseRate) do
if ThirstValue.Value - 1 >= 0 then
ThirstValue.Value = ThirstValue.Value - 1
end
if ThirstValue.Value == 0 then
repeat wait(1)
Hum.Health = Hum.Health - 2
until ThirstValue.Value > 0 or Hum.Health <= 0
end
end
