CCCPaste

New TeleportScript Monster

local TutorialMonster = script.Parent
local Humanoid = TutorialMonster.Humanoid
local PlayerService = game:GetService("Players")




local TrackingStatus = false

local function ChoosePlayer()
    print("NewChoosePlayer")
    return PlayerService:GetPlayers()[math.random(1, #PlayerService:GetPlayers())]
end

local function TrackNewPlayer(NewTarget)
    for i = 10,0,-1 do
        print(i)
        wait(1)
    end
    for _, Player in pairs(game.Players:GetPlayers()) do
        if Player.Character and Player.Character.Humanoid.Health > 0 then

        end
    end
    local Fire = TutorialMonster.TeleportSpirit.Fire:Clone()
    Fire.Parent =NewTarget.HumanoidRootPart
    Fire.Enabled = true
    TutorialMonster.TeleportSpirit.Fire.Enabled = true
    wait(2)
    TutorialMonster.HumanoidRootPart.CFrame = NewTarget.HumanoidRootPart.CFrame - Vector3.new(0,0,20)
    wait(2)
    TutorialMonster.TeleportSpirit.Fire.Enabled = false
    local function Track()
        while TrackingStatus do
            if not TrackingStatus then break end
            if NewTarget.Humanoid.Health == 0 then break end
            Humanoid:MoveTo(NewTarget.HumanoidRootPart.Position)
            wait()
            Fire:Destroy()


        end
    end
    coroutine.resume(coroutine.create(Track))
end

while true do
    while #PlayerService:GetPlayers() == 0 do wait() end
    local NewTarget = ChoosePlayer()
    local Character = NewTarget.Character


    if Character then
        if Character.Humanoid.Health > 0 then
            TrackingStatus = true
            TrackNewPlayer(Character)
            game.ReplicatedStorage.Jumpscare:FireAllClients(true)
            wait(5)
            game.ReplicatedStorage.Jumpscare:FireAllClients(false)
            TrackingStatus = false
        end
    end
    wait()
end