Trouble saving Int Values in a Datastore

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)

Any help would be appreciated, thanks.

1 Like

Please make what you’re trying to achive more clear. What have you tried, and what are you currently doing? We need some code to help you.

1 Like

You don’t need to send the Value’s to the Client and to the server and back.

DataStores loads Players Data Indivigually so you don’t need to worry about sending IntValue’s from and back.

Just do the whole DataStore on the Server and you will be good.

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

	local Char = Player.Character or Player.CharacterAdded:wait()
	local questData = QuestData:GetAsync(Player.UserId)
	local survive = SurvivalData:GetAsync(Player.UserId)
	if survive then
		Char.ThirstVal.Value = survive.CurrentThirst
		Char.HungerVal.Value = survive.CurrentHunger
		Char.Humanoid.Health = survive.CurrentHealth


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)

	Char.ThirstVal.Value = thirst
	Char.HungerVal.Value = hunger
	Char.Humanoid.Health = health

Here’s the code, I’m hoping Im missing something about how datastores work

1 Like

But if I were to change an int Value on the client then attempt to save it on the server, it only saves it on the client from what I’ve seen

1 Like

You should NEVER change values that you save on the client. Only save stuff you’ve changed on the server.

1 Like

But if I do, will the client be able to read what values have been changed from the Server?

1 Like

If a value changes from the server-side then all the clients can see it