Ban System not working?

Hello everyone my ban system is partly not working. The BoolValue says that banned equals true but it will not kick me from the game.
My script:

local datastore = game:GetService('DataStoreService'):GetDataStore('Banned players')
game.Players.PlayerAdded:Connect(function(player)
	local bannedval = Instance.new('BoolValue', player)
	bannedval.Name = 'Banned'
	if player.Banned.Value == true then
		player:Kick('You have been banned form the game!')
	end
	local data
	local succes, ermes = pcall(function()
		data = datastore:GetAsync(player.UserId)
	end)
	if succes then
		bannedval.Value = data
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local succes, ermes = pcall(function()
		datastore:SetAsync(player.UserId, player.Banned.Value)
	end)
end)

image
As you can see the value is set to true. So if someone can help me figure out whats wrong that would be great!

1 Like

Hello! I am pretty sure it is because it is checking the value before it is saved! You see that bannedval.Value = data? That is where it checks if the user is banned or not (I know you know, just reapeting to make sure :+1: ) But basicly move the if statement below the data check so it checks if the user is banned or not.

The reason why you check and it says it is true, is because it does it after the check but it cant be noticed

1 Like

Lol that was simple thanks for reminding me!

1 Like