Saving Bool or Int Value

datastores are just like tables

because you are in studio, i’ve set the setasync so it doesn’t work on studio, to prevent data loss

only 1 localplayer when in localscript so what are u talking abt

but that localscript gets replicated to all players, which means a lot of local scripts running the same code, also, never use clients for a simple datastore like this

Sorry! Forgot some things! this should make a value under a player and save it if it changes. Why did you want to put the value in lightning by the way?

local DSS = game:GetService("DataStoreService")
local thisDataStore = DSS:GetDataStore("PixelBootsDataStore")
local players = game:GetService("Players")
local runService = game:GetService("RunService")

local defaultData = 2 --set this to whatever you'd like

players.PlayerAdded:Connect(function(plr)
	local pixelBoots = Instance.new("NumberValue")
	pixelBoots.Name = "PixelBoots"
	pixelBoots.Parent = plr
	local data
	local success, response = pcall(function()
		data = thisDataStore:GetAsync(plr.UserId)
	end)
	if success then
	  if data then
		pixelBoots.Value = data.PixelBoots
	  else
		pixelBoots.Value = defaultData
	  end
	  plr:SetAttribute("HasLoadedDataStore", true)
	end
end)
players.PlayerRemoving:Connect(function(plr)
	local pixelBoots = plr.PixelBoots
	local data = {pixelBoots.Value}
	local hadLoadedAttribute = plr:GetAttribute("HasLoadedDataStore")
	local success, response = pcall(function()
		if not runService:IsStudio() and hadLoadedAttribute == true then
			thisDataStore:SetAsync(plr.UserId, data)
		end
	end)
end)

Because, you don’t use lighting for things, so I thought I could use it to store values.

My recommendation is to store the player’s data on a folder created for each player on join in serverstorage, but that may be advanced for you, if it is then just save values into a player instance, because you can also access that data with local scripts (clients cannot access serverscriptservice and serverstorage because they do not get replicated for them)

Also tell me if the script worked, (won’t work in-studio)
I remade it so it can work with studio if you want

local DSS = game:GetService("DataStoreService")
local thisDataStore = DSS:GetDataStore("PixelBootsDataStore")
local players = game:GetService("Players")
local runService = game:GetService("RunService")

local canRunInStudio = true --change this to whatever you'd like

local defaultData = 2 --set this to whatever you'd like

players.PlayerAdded:Connect(function(plr)
	local pixelBoots = Instance.new("NumberValue")
	pixelBoots.Name = "PixelBoots"
	pixelBoots.Parent = plr
	local data
	local success, response = pcall(function()
		data = thisDataStore:GetAsync(plr.UserId)
	end)
	if success then
	  if data then
		pixelBoots.Value = data.PixelBoots
	  else
		pixelBoots.Value = defaultData
	  end
	  plr:SetAttribute("HasLoadedDataStore", true)
	end
end)
players.PlayerRemoving:Connect(function(plr)
	local pixelBoots = plr.PixelBoots
	local data = {pixelBoots.Value}
	local hadLoadedAttribute = plr:GetAttribute("HasLoadedDataStore")
	local success, response = pcall(function()
		if (not runService:IsStudio() or canRunInStudio == true) and hadLoadedAttribute == true then
			thisDataStore:SetAsync(plr.UserId, data)
		end
	end)
end)

I can’t tell you right now, because I had to go and I’m on my phone right now.

It doesn’t work, I’m checking the value in studio and it doesn’t save everytime I change it.

Hello? Can someone help? (30 letters)