I’m hoping I can explain what I need since my code is a mess trying to figure this out myself.
I am trying to save int values on a datastore but I’m having trouble with sending the values to the server whenever the player leaves so that they can be saved and sending the values to the client whenever the player has joined the server(If This even is the write way of doing this)
local QuestData = game:GetService("DataStoreService"):GetDataStore("Quests")
local RS = game:GetService("ReplicatedStorage")
local SurvivalData = game:GetService("DataStoreService"):GetDataStore("Survival")
local QuestComplete = RS.QuestComplete
local SendSurvival = RS.SurvivalToClient
local SentSurvival = RS.SurvivalToServer
game.Players.PlayerAdded:connect(function(Player)
local Char = Player.Character or Player.CharacterAdded:wait()
local questData = QuestData:GetAsync(Player.UserId)
local survive = SurvivalData:GetAsync(Player.UserId)
if survive then
print(survive.CurrentHunger)
print(survive.CurrentHealth)
Char.ThirstVal.Value = survive.CurrentThirst
Char.HungerVal.Value = survive.CurrentHunger
Char.Humanoid.Health = survive.CurrentHealth
SendSurvival:FireClient(Player,Char.ThirstVal.Value,Char.HungerVal.Value,Char.Humanoid.Health)
end
Client:
local RS = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local MaxWeightEvent = RS.SkinMax
local SentSurvival = RS.SurvivalToClient
local Sending = RS.SurvivalToServer
local Char = player.Character or player.CharacterAdded:Wait()
local skin = require(RS.Skins)
SentSurvival.OnClientEvent:Connect(function(thirst,hunger,health)
Char.ThirstVal.Value = thirst
Char.HungerVal.Value = hunger
Char.Humanoid.Health = health
end)
Here’s the code, I’m hoping Im missing something about how datastores work