Invalid UTF-8 Character

I’m confused about what to do here. I’m making a banning system and this is my banning code specifically. However, it states this error:

(Cannot store dictionary in a table, Datastores only accept valid UTF-8 Characters)

I’m not really sure how to change my code or what to do to make this work

game.ReplicatedStorage.AdminSystems.Ban.OnServerEvent:Connect(function(player, target, reason, duration)
	if target ~= 'PokeCedGo' or "iEllaSmh" then
		
		local uid = game.Players:GetUserIdFromNameAsync(target)
		
		BannedPlayers:SetAsync(uid, {
			["Time"] = duration, 
			["Moderator"] = player.Name,
			["Reason"] = reason
			
	
		})
		
		local data = {
			["target"] = target,
	
		}
		
		MessagingService:PublishAsync("BAN_PLAYER", data)
		
		game.Players:FindFirstChild(target):Kick(reason)

	end
end)```

Meaning you can only store strings, integers, etc.

ROBLOX and their datastores don’t allow for saving instances, therefore you’re going to have to make a workaround. If you’re trying to save a player, instead of saving them, save their UserID. Check this article for more information.

What if I do say

local newplayer = tostring(player.Name)

and send that instead
would that work?

It could, yes, but username checking isn’t necessarily the best thing for banning. For instance; they can change their username, now what? You have to keep updating when they update their name? No thanks. Comparing their UserID is a much better solution.

I see, okay ty, let me go try it now

Also

Are you sure about this line? It basically will ban anyone since the if statement will always be true (Lua treats strings as true)

Perhaps you meant:

if target ~= 'PokeCedGo' and target ~= "iEllaSmh" then

ty! I’ve been trying to do other methods and I’m coming to no luck on how to save it as a UserId.
I’ve attempted to remove the the “Moderator” in the dictionary but same error.

What I don’t understand is that I am banning the player through their UserId (assuming the local uid is what that is)

and the duration is a numbervalue (should be acceptable) and I used a tostring method for the player (“person banning”)

Initially, my plan was to fire a remoteevent to the server, and changed a datastore value “Ban” to say = 1

everytime they join, if the value is 1, they’d get kicked

However, with that method, unless you know, how would unbanning them work?

Am I able to access players datastore data even though there not in the game so I can change their ban value = 0 to unban them?

Can you double-check to see if all of the values are acceptable? Like for example what exactly is the reason

You can also try printing out all of the values to see for yourself if they are right

This is getting off-topic, you should create a new thread about that issue

This thread is only about the UTF-8 issue

Good news! I checked the data being sent and turns out duration was nil which fixed the issue!
No I just have to fix the issue that they can still rejoin