Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is My NumberValue.Value Not Saving When Changed In Properties/Command Bar?

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local wins = Instance.new("NumberValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats

	local data
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-Wins")
	end)
	
	if success then
		wins.Value = data
	else
		print("data failed")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId.."-Wins", player.leaderstats.Wins.Value)
	end)
	
	if success then
		print("data saved")
	else
		print("data failed")
		warn(errormessage)
	end
end)

When I open up the Explorer tab, and find the value and change it in the Properties window, it does not save, even when it prints, "data saved". It also does not save when I update the value in the Command Bar. Why is that, and how can I resolve this error?

2 answers

Hi I am not sure this will work but you can try it:

where you have this set of code:

local data
local success, errormessage = pcall(function()
    data = myDataStore:GetAsync(player.UserId.."-Wins")
end)

if success then
    wins.Value = data
else
    print("data failed")
    warn(errormessage)
end

change to this:

local success,data = pcall(function()
	return  myDataStore:GetAsync(player.UserId.."-Wins")
end)

if success and data then 
wins.Value = data
else
 print("data failed")
    warn(errormessage)
end

1 comment

0

Where is the errormessage then?

  • If you're not using API on studio, datastore won't work
  • What is NumberValue? Don't you mean IntValue? -Try changing NumberValue to IntValue, since "wins" is probably a number.

1 comment

0

Yes, I turned on the API, though, you can't have an integer amount of wins.

This discussion is preserved as it was. New answers, comments, and votes are closed.