Datastore script not saving data

HI out there i am learning to script and i made a datastore script that is supposed to store cash but its not saving and giving me an error message. I know i have been creating a lot of topics recently but that’s because i ak learning. Can someone help me with this anyways

THE CODE

local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“DataStore”)

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new (“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player

    local Cash  = Instance.new ("IntValue") 
        Cash.Name = "Cash"  
        Cash.Parent = leaderstats 
local playerUserId = "Player_"..player.UserId 
         

--Load Data
local data
local success,errormessage = pcall(function() 
	data = myDataStore:GetAsync(playerUserId)	 
end) 

if success then 
	Cash.Value = data 
	--Set our data equal to the current cash 
end

end)

local data
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “Player_”…player.UserId

local data = player.leaderstats.Cash.Value 
local success, errormessagge =  pcall (function()  
	myDataStore:SetASync(playerUserId,data)
end) 


if success then 
	print ("Data Successfully Saved") 
else 
	print("There was an error!") 
	warn ("errormessage")
end

end)``

What is your output printing out, have you turned on “Enable studio access to API Services”?

yes i did enable it

30 char fro irritating roblox

again, what is your output printing out?

wait asec im sending the screenshot

Change this to myDataStore:SetAsync(playerUserId,data) You has a spelling error with capital S

1 Like

Tysm i just dont know how mcuh do i thank you…Thanks a lot!

1 Like