How to save a local value in a data store

it jumps to 0 and then does -5,

ok before I address that, what is the function of the script? to reduce the energy slowly?

sorry if i misunderstood but i think you mean this

yes i did i didnt see that my bad

1 Like

You can simply just use remote events.

i have, its just not sending any data from the client to the server

Can you send the arguments which you are supplying to the remote?

try swapping out the repeat for whiles?

game.Players.PlayerRemoving:Connect(function()
	
	game.ReplicatedStorage.DatasToServerRM:FireServer(game.Players.LocalPlayer.PlayerNeeds.Energy.Value)
	
end)

and the server recieving


game.ReplicatedStorage.DatasToServerRM.OnServerEvent:Connect(function(player, EnergyVal)

	local Success, ErrorMessage = pcall(function()

		PlayerNeedsDataStore:SetAsync(plr.UserId, EnergyVal)

	end)
	
	if Success then
		
		print("PlayerNeeds have been successfully saved")
		
	else
		
		warn(ErrorMessage)
		
		print("there was an error while saving data")
		
	end

	
end)

is there another script that is manipulating the value of energyvalue?

Yeah no point in firing a remote when the player is leaving lol, hence the args are nil

this part of the script is working right?