Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- players = game.Players
- localPlayer = players.LocalPlayer
- bodyPosition = nil
- bodyGyro = nil
- currentTarget = nil
- function getCFrameBehindPlayer(targetPlayer)
- if targetPlayer.Character ~= nil then
- local targetTorso = targetPlayer.Character:FindFirstChild("HumanoidRootPart")
- if targetTorso ~= nil then
- local torsoRotation = targetTorso.CFrame:toAxisAngle()
- local bottomOfTorso = targetTorso.CFrame.p-Vector3.new(0,targetTorso.Size.Y/2,0)
- local behindTorso = CFrame.new(bottomOfTorso-targetTorso.CFrame.lookVector*1.2)+Vector3.new(0,1,0)
- return behindTorso*CFrame.Angles(torsoRotation.X,torsoRotation.Y,torsoRotation.Z)
- else
- currentTarget = nil
- end
- else
- currentTarget = nil
- end
- end
- function teleportBehindPlayer(playerToTeleport,targetPlayer)
- if playerToTeleport.Character ~= nil and targetPlayer.Character ~= nil then
- local playerTorso = playerToTeleport.Character:FindFirstChild("HumanoidRootPart")
- local targetTorso = targetPlayer.Character:FindFirstChild("HumanoidRootPart")
- if playerTorso ~= nil and targetTorso ~= nil then
- local behindPlayer = getCFrameBehindPlayer(targetPlayer)
- playerTorso.CFrame = behindPlayer
- if typeof(bodyPosition) == "Instance" and bodyPosition:IsA("BodyPosition") then
- bodyPosition.Position = behindPlayer.p
- bodyPosition.MaxForce = Vector3.new(5e9,5e9,5e9)
- end
- if typeof(bodyGyro) == "Instance" and bodyGyro:IsA("BodyGyro") then
- bodyGyro.CFrame = behindPlayer
- bodyGyro.MaxTorque = Vector3.new(5e9,5e9,5e9)
- end
- else
- currentTarget = nil
- end
- else
- currentTarget = nil
- end
- end
- game.ReplicatedStorage.Remotes.UpdateTarget.OnClientEvent:connect(function(targetName)
- local targetPlayer = players:FindFirstChild(targetName)
- if targetPlayer ~= nil and targetPlayer:IsA("Player") and targetPlayer ~= localPlayer then
- wait(1)
- currentTarget = targetPlayer
- teleportBehindPlayer(localPlayer,targetPlayer)
- if currentTarget ~= nil and currentTarget.Character ~= nil and currentTarget.Character:FindFirstChildOfClass("Humanoid") then
- currentTarget.Character:FindFirstChildOfClass("Humanoid").Died:connect(function()
- if typeof(bodyPosition) == "Instance" and bodyPosition:IsA("BodyPosition") then
- bodyPosition.MaxForce = Vector3.new(0,0,0)
- end
- if typeof(bodyGyro) == "Instance" and bodyGyro:IsA("BodyGyro") then
- bodyGyro.MaxTorque = Vector3.new(0,0,0)
- end
- end)
- else
- currentTarget = nil
- end
- else
- currentTarget = nil
- end
- end)
- function setupCharacter(char)
- bodyPosition = Instance.new("BodyPosition")
- bodyPosition.D = 100
- bodyPosition.MaxForce = Vector3.new(0,0,0)
- bodyPosition.P = 8000
- bodyGyro = Instance.new("BodyGyro")
- bodyGyro.D = 100
- bodyGyro.MaxTorque = Vector3.new(0,0,0)
- bodyGyro.P = 8000
- bodyPosition.Parent = char:WaitForChild("HumanoidRootPart")
- bodyGyro.Parent = char.HumanoidRootPart
- char:WaitForChild("Humanoid").Died:connect(function()
- currentTarget = nil
- if typeof(bodyPosition) == "Instance" and bodyPosition:IsA("BodyPosition") then
- bodyPosition.MaxForce = Vector3.new(0,0,0)
- end
- if typeof(bodyGyro) == "Instance" and bodyGyro:IsA("BodyGyro") then
- bodyGyro.MaxTorque = Vector3.new(0,0,0)
- end
- end)
- end
- if localPlayer.Character ~= nil then
- setupCharacter(localPlayer.Character)
- end
- localPlayer.CharacterAdded:connect(function(char)
- setupCharacter(char)
- end)
- game:GetService("RunService").RenderStepped:connect(function()
- if currentTarget ~= nil and currentTarget:IsA("Player") and currentTarget.Character ~= nil then
- local behindPlayer = getCFrameBehindPlayer(currentTarget)
- if behindPlayer ~= nil and typeof(bodyPosition) == "Instance" and bodyPosition:IsA("BodyPosition") then
- bodyPosition.Position = behindPlayer.p
- bodyPosition.MaxForce = Vector3.new(5e9,5e9,5e9)
- end
- if typeof(bodyGyro) == "Instance" and bodyGyro:IsA("BodyGyro") then
- local targetTorso = currentTarget.Character:FindFirstChild("HumanoidRootPart")
- if targetTorso ~= nil then
- bodyGyro.CFrame = targetTorso.CFrame
- bodyGyro.MaxTorque = Vector3.new(5e9,5e9,5e9)
- end
- end
- else
- currentTarget = nil
- end
- end)
Add Comment
Please, Sign In to add comment