Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i setup a Permanent death event?

How do i create a Permanent death event script, like when i type like an command for example PD on or something it activates and when a Player dies they get banned for a certain time 10 hours for example and i can also turn it off with PD off?

Help would be appreciated

1 comment

0

Hey sorry if my code didn't work you should test it again, I just added respawn system so players can get back into the game

1 answer

I would say use attributes. First, you can do

local HOURS_DEAD = 10 --Set this to how many hours the player should die for before being able to join
local Players = game:GetService("Players") 
Player.PlayerAdded:Connect(function(plr)
	local dTime = 0
	if plr:GetAttribute("DeathTime") == nil then
		plr:SetAttribute("DeathTime", 0)
	end
	if plr:GetAttribute("Died") == true then
		if plr:GetAttribute("DeathTime") ~= nil then
			dTime = plr:GetAttriubte("DeatTime")
		end
		if os.time() - dTime <  3600*HOURS_DEAD then 
			plr:SetAttribute("Died", true)
			local date = os.time() - dTime
			plr:Kick("You will respawn in "..date/14400 .. " hours!")
		elseif os.time() - dTime > 3600*HOURS_DEAD then
			plr:SetAttribute("Died", false)
		end
	elseif plr:GetAttribute("Died") == nil then
		plr:SetAttriubte("Died", false)
	end
end)

This code should be able to be put in a Script in ServerScriptService, it basically checks if the player is dead and if they are it kicks them

Finally, you need a code to kill the player. This should work in a script, I just programmed it as if the parent of the script is a kill brick

local Players = game:GetService("Players")
local function killPlayer(plr)
	local name = plr:FindFirstAncestorWhichIsA("Model").Name
	local player = Players:FindFirstChild(name)
	player:SetAttribute("Died", true)
	player:SetAttribute("DeathTime", os.time())
	player:Kick("You will respawn in 10 Hours!!")
end

script.Parent.Touched:Connect(killPlayer)

I spent a long time on this script I really hope it helped! The only thing you need to actually kill the player/ban them is this

player:SetAttribute("Died", true)
player:SetAttribute("DeathTime", os.time())
player:Kick("You will respawn in 10 Hours!!")

Where player contains the person's Player object from game:GetService("Players")

This discussion is preserved as it was. New answers, comments, and votes are closed.