How do I make this rank door teleport to spawn instead of kill?

I want to change the script of this door so players won’t die when they touch it, but instead teleport to the spawn without losing items.

Does anyone know how to do that?

GroupIdenabled = true
GroupId = 6741421 -- Group ID
min = 2 -- Rank that can get in
max = 255
--Item ID--
ItemIdenabled = false

local KilluponTouched = true
local WaitTime = 0.2 --Amount of time door remains open before closing.
DoorTransparency = 1 -- Door transparency
Door = script.Parent
Q = false

if GroupIdenabled == true then
	function Touched(Part)
		local Human = Part.Parent:findFirstChild("Humanoid")
		if Q then return end
		Q = true 
		if Part.Parent then
			p=game.Players:getPlayerFromCharacter(Part.Parent)
			if p then 
				if p:GetRankInGroup(GroupId) >= min and p:GetRankInGroup(GroupId) <= max or (CheckExceptions(Human.Parent.Name))then
					AccessGranted() 
				else
					print("No Access")
					if KilluponTouched then Part.Parent:breakJoints()
						wait(WaitTime)
					end end end end  Q = false end end

--Opens Door If Player's Rank was Correct--
function AccessGranted()
	print("Access Granted")
	Door.Transparency = 1
	Door.CanCollide = false
	wait(WaitTime)
	Door.CanCollide = true
	Door.Transparency = DoorTransparency
end






Door.Touched:connect(Touched)
--This is the function that would probably kill the player
if KilluponTouched then Part.Parent:breakJoints()
GroupIdenabled = true
GroupId = 6741421 -- Group ID
min = 2 -- Rank that can get in
max = 255
--Item ID--
ItemIdenabled = false

local KilluponTouched = true
local WaitTime = 0.2 --Amount of time door remains open before closing.
DoorTransparency = 1 -- Door transparency
Door = script.Parent
Q = false

if GroupIdenabled == true then
	function Touched(Part)
		local Human = Part.Parent:findFirstChild("Humanoid")
		if Q then return end
		Q = true 
		if Part.Parent then
			p=game.Players:getPlayerFromCharacter(Part.Parent)
			if p then 
				if p:GetRankInGroup(GroupId) >= min and p:GetRankInGroup(GroupId) <= max or (CheckExceptions(Human.Parent.Name))then
					AccessGranted() 
				else
					print("No Access")
					if KilluponTouched then Part.Parent:SetPrimaryPartCFrame(spawnlocation.CFrame) -- set this to your position of spawn
						wait(WaitTime)
					end end end end  Q = false end end

--Opens Door If Player's Rank was Correct--
function AccessGranted()
	print("Access Granted")
	Door.Transparency = 1
	Door.CanCollide = false
	wait(WaitTime)
	Door.CanCollide = true
	Door.Transparency = DoorTransparency
end
2 Likes

The door isn’t working now, What do I do?

Script (with my modifications):

local SpawnLocation = workspace.SpawnLocation
GroupIdenabled = true
GroupId = 6741421 -- Group ID
min = 2 -- Rank that can get in
max = 255
--Item ID--
ItemIdenabled = false

local KilluponTouched = true
local WaitTime = 0.2 --Amount of time door remains open before closing.
DoorTransparency = 1 -- Door transparency
Door = script.Parent
Q = false

if GroupIdenabled == true then
	function Touched(Part)
		local Human = Part.Parent:findFirstChild("Humanoid")
		if Q then return end
		Q = true 
		if Part.Parent then
			p=game.Players:getPlayerFromCharacter(Part.Parent)
			if p then 
				if p:GetRankInGroup(GroupId) >= min and p:GetRankInGroup(GroupId) <= max then
					AccessGranted() 
				else
					print("No Access")
					if KilluponTouched then Part.Parent:SetPrimaryPartCFrame(SpawnLocation.CFrame)
						wait(WaitTime)
					end end end end  Q = false end end

--Opens Door If Player's Rank was Correct--
function AccessGranted()
	print("Access Granted")
	Door.Transparency = 1
	Door.CanCollide = false
	wait(WaitTime)
	Door.CanCollide = true
	Door.Transparency = DoorTransparency
end

You need to actually grab the parts CFrame from workspace. :SetPrimaryPartCFrame(workspace.NAMEOFPART.CFrame) – Name of part being your spawn locations part name in workspace

1 Like
GroupIdenabled = true
GroupId = 6741421 -- Group ID
min = 2 -- Rank that can get in
max = 255
--Item ID--
ItemIdenabled = false

local KilluponTouched = true
local WaitTime = 0.5 --Amount of time door remains open before closing.
Door = script.Parent
Q = false

if GroupIdenabled == true then
	function Touched(Part)
		local Human = Part.Parent:findFirstChild("Humanoid")
		if Q then return end
		Q = true 
		if Part.Parent then
			p = game.Players:getPlayerFromCharacter(Part.Parent)
			if p then 
				if p:GetRankInGroup(GroupId) >= min and p:GetRankInGroup(GroupId) <= max then
					AccessGranted() 
				else
					print("No Access")
					if KilluponTouched then Part.Parent:SetPrimaryPartCFrame(workspace.SpawnLocation.CFrame)
						wait(WaitTime)
					end end end end  Q = false end end

--Opens Door If Player's Rank was Correct--
function AccessGranted()
	print("Access Granted")
	Door.Transparency = 1
	Door.CanCollide = false
	wait(WaitTime)
	Door.CanCollide = true
end

The tiny little “p” in there is erroring.

p = game.Players:getPlayerFromCharacter(Part.Parent)