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 make an enemy teleport?

i have this teleporting door script (it fades in and out, works perfectly for normal players) but it won't teleport an enemy, or npc. the npc/enemy has a humanoid (it's the drooling zombie made by roblox) this is the teleport script

local TeleportationDoorEvent = game.ReplicatedStorage.TeleportationDoorEvent

local Door1 = script.Parent.Door1 
local Door2 = script.Parent.Door2

local debounce = false




Door1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			debounce = true

			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

			if plr then
				TeleportationDoorEvent:FireClient(plr)
				wait(0.8)
				hit.Parent.HumanoidRootPart.CFrame = Door2.CFrame
				wait(2)
				debounce = false
			end
		end
	end
end)




-- (door 2 is removed so you can only teleport one way)

1 comment

0

local TeleportationDoorEvent = game.ReplicatedStorage.TeleportationDoorEvent local Door1 = script.Parent.Door1 local Door2 = script.Parent.Door2 local debounce = false Door1.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if not debounce then debounce = true hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Door2.CFrame) debounc

2 answers

local TeleportationDoorEvent = game.ReplicatedStorage.TeleportationDoorEvent

local Door1 = script.Parent.Door1 
local Door2 = script.Parent.Door2

local debounce = false




Door1.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if not debounce then
            debounce = true

            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

            if plr then
                TeleportationDoorEvent:FireClient(plr)
end
                wait(0.8)
                if hit.Parent:FindFirstChild("HumanoidRootPart",true) then
hit.Parent.HumanoidRootPart.CFrame = Door2.CFrame
end
                wait(2)
                debounce = false
            end
        end
    end
end)




-- (door 2 is removed so you can only teleport one way)

Maybe This Will work

this will make you teleporting to door2 when door1 has been touched


local TeleportationDoorEvent = game.ReplicatedStorage.TeleportationDoorEvent
 
local Door1 = script.Parent.Door1
local Door2 = script.Parent.Door2
 
local debounce = false
 
Door1.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if not debounce then
            debounce = true
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Door2.CFrame)
	          debounce = false
	       end
	   end
     end
end)


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