[Solved!] Datastorage not saving and IntValue problem!

Hey, I’m learning datastorage and in my script none of my data is save, I’m also getting this error as well in my ouput.

Also in my pcall function it’s saying is successfully loaded and saved my data as well so I’m just a bit confused.
I feel like I’m doing something obviously wrong and if anyone knows the solution to my issue it would be great help.

local DataStorage = game:GetService("DataStoreService")
local DataCoinsSaveSlot = DataStorage:GetDataStore("DataCoinSaveSlot")

local function PlayerAddedFunction(Player)
	local LeaderFolder = Instance.new("Folder", Player)
	LeaderFolder.Name = "leaderstats"


	local DataCoinValue = Instance.new("IntValue", LeaderFolder)
	DataCoinValue.Name = "Coins"
	
	local Success, Unsuccessful = pcall(function()
		return DataCoinsSaveSlot:GetAsync(Player.UserId)
	end)
	
	
	if Success then
		DataCoinValue.Value = DataCoinsSaveSlot
		print("coins saved")
	else
		DataCoinValue.Value = 0
		print("coins didn't load?")
	end

end
	
game.Players.PlayerAdded:Connect(PlayerAddedFunction)


local function PlayerLeavingFunction(Player)
	local Leaderstats = Player:WaitForChild("leaderstats")
	local DataCoinValue = Leaderstats:WaitForChild("Coins")
	

	local Success, Unsuccessful = pcall(function()
		DataCoinsSaveSlot:SetAsync(Player.UserId, DataCoinValue.Value)
	end)
	
	if Success then
		print("coins saved")
	else
		print("coins didn't save error")
	end
	
end


game.Players.PlayerRemoving:Connect(PlayerLeavingFunction)

game:BindToClose(function()
	wait(1)
end)
1 Like

I think the problem here is you trying to save an Instance inside of an IntValue which can only save numbers.

1 Like

Jesus thank you I didn’t realize I set it to the wrong thing the entire time until you said that and was so confused, thank you lol.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.