Datastore script broken

I want to make a datastore script for my leaderboard stats.
Script doesn’t work, shows this error:
image
My script:

local DataStoreService = game:GetService('DataStoreService')
local playerData = DataStoreService:GetDataStore('PlayerData')

local function onPlayerJoin(player)
	local leaderstats = Instance.new('Folder')
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = player
	
	local miles = Instance.new('IntValue')
	miles.Name = 'miles'	
	miles.Parent = leaderstats
	
	local playerUserId = 'Player_'.. player.UserId
	local data = playerData:GetAsync(playerUserId)
	
	if data then
		miles.Value = data
	else
		miles.Value = 0
	end
end


local function onPlayerExit(player)
	local success, err = pcall(function()
		local playerUserId = 'Player_'..player.UserId
		
		playerData:SetAsync(playerUserId, player.leaderstats.miles.Value)
	end)
	if not success then
		warn ('Could not save data!')
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)

Line 1? Could you show the entire script?

Original message edited - you should be able to see it!
Apologies.

Have you applied the script?
image

Do you have this turned on? You might need to apply the script from the drafts then
image

The Script you posted works perfectly fine for me. No error for me

Do you have API services on? This could be the problem