Help with Ban on Death Script

I want to achieve a way to ban players when they die. The Banning Does Not Work. Tried looking it up on google, however I have little to none scripting experience. I’m making a game where if you die, you get banned from the game for 30 minutes.
Heres a Video:
https://cdn.discordapp.com/attachments/961537136711065631/963919437818392616/2022-04-13_17-49-35.mp4
Here’s the script:

local OwnerID={
	1829034891,
	2323040617
}

local CoOwnerID={}
local GameManagerID={}
local HeadAdminID={}
local DevID={}
local AdminID={}
local ModID={}
local TrialModID={}
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if BanCooldown == true then
			plr:Kick("You are stil banned from the game! Join back later.")
		end
		if char.Humanoid.Health == 0 then
			if plr.UserId == OwnerID or CoOwnerID or GameManagerID or HeadAdminID or DevID or AdminID or ModID or TrialModID then
			else
				plr:Kick("You Died! Join back in 30 seconds.")
				local BanCooldown = true
				wait(30*60)
				local BanCooldown = false
			end
		end
	end)
end)
1 Like

@STOPEATCAK

First of all, the script checks for 0 health when the player joins. Use the 1.

plr.Character.Humanoid.Died:Connect(function()
--code here
end)

function then set the ban value to true, then kick the player. Now that you have the kick part in, you need data store.
In replicated storage, create a remote event called “Banplr”
In a local script in startergui, put this:

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()

game.ReplicatedStorage.Banplr:FireServer()

end)

In a server script put:

local DSS = game:GetService("DataStoreService"):GetDataStore("Bans")



game.ReplicatedStorage.Banplr.OnServerEvent:Connect(function(plr)
	pcall(function()
		DSS:SetAsync(plr.UserId.."banned", "1"..os.time())
		wait(5)
		plr:Kick()
	end)
end)

game.Players.PlayerAdded:Connect(function(plr)
	pcall(function()
		if string.sub(DSS:GetAsync(plr.UserId.."banned"), 1, 1) == "1" then
			if tonumber(string.sub(DSS:GetAsync(plr.UserId.."banned"), 2, #DSS:GetAsync(plr.UserId.."banned"))) + 1800 <= os.time()  then
				DSS:SetAsync(plr.UserId.."banned", "2")
			else
				plr:Kick("Nope, still banned")
			end
		end
	end)
	
end)

If this does not work send me the error message

3 Likes

Heres my issue. When they get kicked they don’t get banned, I had to modify it a bit. Here is the vid: https://cdn.discordapp.com/attachments/948092628317122600/963927056809353236/2022-04-13_18-19-49.mp4
Here is the current script thats in maingame:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		plr.Character.Humanoid.Died:Connect(function()
			local BanCooldown = true
			plr:Kick("You Died!")
		if BanCooldown == true then
					plr:Kick("You're Banned.")
		end
	end)
end)
end)

MainGame is the main script for the game. Its mainly put in serverscript service and I put the more important things there. To clear up confusion :slight_smile:
Heres something else I found while copy n pasting
image

image_2022-04-13_183222847

1 Like

why do you need ban cooldown, you only loose your health once

ban cooldown is ban time, incase if you didnt notice.
The player also gets banned for 30 minutes only.

1 Like

Also what does this mean? I know nothing about datastores so I’m pretty sure this is about datastores.

Please remember that I’m not good with datastores, I’m really new to them @shipmaster2410

1 Like

I know, that’s why I sent you the full script and not explain it to you because you would not understant :slight_smile:

Although I don’t understand, thanks : )

1 Like