Permanently banned on death | Not working

  1. What do you want to achieve? Keep it simple and clear!
    A script where it make’s you permanently banned when on death.

  2. What is the issue? Include screenshots / videos if possible!
    The output shows no error on the script, through the script doesn’t work.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried twisting some script, still doesn’t work.

-- a script (not localscript)

local DataStoreService = game:GetService("DataStoreService")
local banDataStore = DataStoreService:getDataStore("banDataStore")

wait(1) -- a delay
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local Humanoid = char:WaitForChild("Humanoid")
		if Humanoid.Died or Humanoid.Health == 0 then -- detects if the player is dead
			player:Kick("Died. You are permanently banned to this game.") -- bans them		
			print("banned player")
		else
			print("unsuccessful")
			local pTGBe = player -- possible problem
		
		local banned
		local success, errormessage = pcall(function()
				banned = banDataStore:GetAsync(PTGBe.UserId)
				end)
				if banned == true then
				player:Kick("Your dead. Your permanently banned.") -- bans them again if they rejoined
				print("kicked player & successfully kicked someone")
			else
				print("unsuccessful")
					end
			end
	end)
end)

You’re only checking if Humanoid.Died when CharacterAdded fires, which is once, since that’s nested inside PlayerAdded, and the humanoid isn’t dead when they first join the game. Try separating them out, and instead of checking for Died right away, bind the Died event to another function to process it, so it can happen at any point. It’d look something like:

local banDataStore = game:GetService("DataStoreService"):getDataStore("banDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local banned = false
	local success, errormessage = pcall(function()
		banned = banDataStore:GetAsync(player.UserId)
	end)
	
	if banned then
		player:Kick("Your dead. Your permanently banned.")
		print("kicked player & successfully kicked someone")
	else
		player.CharacterAdded:Connect(function(char)
			local Humanoid = char:WaitForChild("Humanoid")
			Humanoid.Died:connect(function()
				player:Kick("Died. You are permanently banned to this game.")	
				print("banned player")
			end)
		end)
	end
end)
2 Likes