Do you have anything that keeps track of deaths? It’s easy to script everything into one, but if you’re already keeping track of deaths elsewhere, or if you plan on reusing this (multiple doors), it would be better to understand some specifics first.
What you can do is store the number of deaths in an IntValue using a Data Store. After that, you can put this script inside the door.
local Door = script.Parent
local requiredDeaths = 10 -- Amount of deaths the player needs to open the door.
local timeOpened = 2 -- Seconds that the door will be opened.
Door.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil then
local Players = game:FindService("Players")
local plr = Players:GetPlayerFromCharacter(humanoid.Parent)
if plr.leaderstats:WaitForChild("Deaths").Value >= requiredDeaths then
Door.CanCollide = false
wait(timeOpened)
Door.CanCollide = true
end
end
end)
There is usually a better approach to this, but I am lazy so the door isn’t going to be the fanciest. Hope this helps.