UserID is not a valid member of Player "Players.EpicTradings

Hey everyone! My output is showing I have a warning (in title). I was following an AlvinBlox tutorial, as I am learning lua. Could someone help me out with this error? The code is pretty messy as well.

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 Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = leaderstats	
	
	local data
	
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(Player.UserID.."-Cash")
	end)
	
	if success then
		Cash.Value = data
		Cash = Cash + 1
	else
		print("error when getting data")
		warn(errormessage)
	end
	
	
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(Player.UserID.."-Cash",Player.LeaderStats.Cash.Value)
	end)
	if success then
			print("datasave completed successfully")
		else
			print("error when saving data, reported to owner")
			warn(errormessage)
		end
end)


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

The property name is UserId, not UserID. Lua(u) is case-sensitive.

1 Like

I thought it worked, but it seems I am still getting the error… I changed it to UserId as well.

Change all occurrences of this. You may have changed only one.

1 Like

You spelled your folder like “leaderstats” but later on used caps

3 Likes

I also noticed you assigned leaderstats to this variable but later you addressed it as LeaderStats

3 Likes