Datastore attempt to compare nil and number

I want to achieve a script that checks if a membership has run out, the problem with this is that i get the error: attempt to compare nil and number, i don’t know what causes this, i’ve already searched for this but none of the posts actually helped me with this problem.

Players.PlayerAdded:Connect(function(Player)
	local MembershipData = MembershipDatastore:GetAsync(MembershipDataKey..Player.UserId)
	if MembershipData then
		while true do
			wait(10)
			if MembershipDataKey.EndsOn < os.time() then
				local Success,ErrorMessage = pcall(function()
					MembershipDatastore:RemoveAsync(MembershipDataKey..Player.UserId)
				end)
				if Success then
					Player:LoadCharacter()
					print("Membership removed from: "..Player.Name)
				else
					print("Error: "..ErrorMessage)
				end
			end
		end
	end
end)
1 Like

The error is on this line,

if MembershipDataKey.EndsOn < os.time() then

It is supposed to be MembershipData.EndsOn not MembershipDataKey.EndsOn.

1 Like

Oh, i didn’t notice that at all, thanks anyway

1 Like