Help with a script that makes the player die forever

I am currently making a script for an admin panel that will be toggleable and make it so that if it is on it will kick any player who dies and if they try to rejoin it will kick them again forever in that specific server.

I am having some issues with this, can anyone help me?

local button = script.Parent
local debounce = false

button.MouseButton1Click:Connect(function()
if debounce == false then
debounce = true

	game.Players.PlayerAdded:Connect(function(plr)
		if plr:GetAttribute("Died") then
			plr:Kick("you already died bozo.")
		end
	end)

	game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function(character)
			character.Humanoid.Died:Connect(function()
				player:Kick("You died!")
				player:SetAttribute("Died")

			end)
		end)
	end)
	
	
	button.BackgroundColor3 = Color3.fromRGB(62, 84, 57)
elseif debounce == true then
	debounce = false
	button.BackgroundColor3 = Color3.fromRGB(84, 61, 61)
end

end)

1 Like

sorry I think the blockqoute broke a bit, here the right version

local button = script.Parent
local debounce = false

button.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		
		
		game.Players.PlayerAdded:Connect(function(plr)
			if plr:GetAttribute("Died") then
				plr:Kick("you already died bozo.")
			end
		end)

		game.Players.PlayerAdded:Connect(function(player)
			player.CharacterAdded:Connect(function(character)
				character.Humanoid.Died:Connect(function()
					player:Kick("You died!")
					player:SetAttribute("Died")

				end)
			end)
		end)
		
		
		button.BackgroundColor3 = Color3.fromRGB(62, 84, 57)
	elseif debounce == true then
		debounce = false
		button.BackgroundColor3 = Color3.fromRGB(84, 61, 61)
	end
end)

I think you should use data stores instead of just attributes, since attributes alone are volatile.

https://www.reddit.com/r/robloxgamedev/comments/zidpmd/how_do_i_make_a_custom_attribute_for_each_player/

thats true and I thought of that but I was unsure of how to make it only kick the player from the server.

Make a table in the serverscript and whenever the player is dies put their userId inside the table. Whenever a player joins the game check if the userid is inside the table. If so kick them again. Will only kick players from that server.

I’m pretty new to scripting and don’t know how to do most of what you said, do you think you could try explaining it in some sort of step-by-step guide? If not thats completely fine but I would really appreciate it.

If your trying to make it so that its a permanent death in-server,
Make a folder of dead players, and when someone dies, create a boolvalue named the player in the folder
When player rejoins, findfirstchild of players name in said folder
If there is the instance in the folder, then kick

I tried this but resetting doesn’t kick me from the game and neither does rejoining?

local button = script.Parent
local debounce = false
local playerswhodied = Instance.new("Folder", workspace)
playerswhodied.Name = "playerswhodied"

button.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		
		
		game.Players.PlayerAdded:Connect(function(plr)
			if playerswhodied:FindFirstChild(plr.Name) then
				plr:Kick("You already died bozo.")
			end
		end)

		game.Players.PlayerAdded:Connect(function(player)
			player.CharacterAdded:Connect(function(character)
				character.Humanoid.Died:Connect(function()
					player:Kick("You died!")
					local died = Instance.new("BoolValue", playerswhodied)
					died.Name = player.Name
				end)
			end)
		end)
		
		
		button.BackgroundColor3 = Color3.fromRGB(62, 84, 57)
	elseif debounce == true then
		debounce = false
		button.BackgroundColor3 = Color3.fromRGB(84, 61, 61)
	end
end)

Check for value when character also respawns.