Ban on death script is not working

Hello!

I have a script that supposedly bans people upon death, I tried it out and it doesn’t seem to work. The regular screen appears “You were kicked from this experience: You’ve been banned! (Error Code:267)” But upon joining the game again, you are still able to play just like regular. I am very new to scripting, so I am not too sure what is going on. The output shows no errors.

Here is the code:

game.Players.PlayerAdded:Connect(function(p)
	-- when they die, save their name and kick them
	p.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function()
			local c = script.BannedUser:Clone()
			c.Value = p.Name
			c.Parent = script
			wait(1)
			p:Kick("You've been banned!")
		end)
	end)
	
	-- if they rejoin and they've been banned, kick them again
	for i,v in pairs(script:GetChildren()) do
		if v.Value == p.Name then
			p.Kick("You've been banned!")
		end
	end

I have a StringValue ‘Banned User’ attached to the script, if that helps provide information
Screenshot (16)

Thank you, and all help is welcome!

Servers close when the last player leaves. You don’t seem to be storing anything involving the player being kicked outside of the server you’re working with. If you want data that persists even after the players leave, I suggest looking into DataStoreService. It’s an awesome tool that gives you this capability. :slight_smile:

Some steps would be:

  1. Kick the user and store a value in DataStore that says this player is banned (this could be just a simple true or false/nil value in your case)
  2. When the player loads back in, fetch that data store you saved to
  3. If that value is true, it means they’re banned and you should kick them, otherwise just let them play

Keep in mind, DataStore is a slightly intermediate topic to get into. I recommend looking at some documentation like this.

3 Likes