local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local localPlayer = Players.LocalPlayer
local function findplayer()
local nearest = nil
local shortestDistance = math.huge
local Character = localPlayer.Character
if not Character or not Character:FindFirstChild("HumanoidRootPart") then return nil end
for _, player in ipairs(Players:GetPlayers()) do
if player ~= localPlayer and player.Character then
local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
if rootPart then
local distance = (rootPart.Position - Character.HumanoidRootPart.Position).Magnitude
if distance < shortestDistance then
shortestDistance = distance
nearest = player
end
end
end
end
return nearest
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.T then
local target = findplayer()
if not target or not target.Character then return end
local torso = target.Character:FindFirstChild("Torso")
or target.Character:FindFirstChild("UpperTorso")
local torsoCollide = torso and torso:FindFirstChild("Torso_Collide")
if not torso then return end
local localRoot = localPlayer.Character and localPlayer.Character:FindFirstChild("HumanoidRootPart")
if not localRoot then return end
local direction = torsoCollide
and (torsoCollide.Position - localRoot.Position).Unit
or Vector3.new(0, 0, -1)
local args = {
"Throw",
direction,
torsoCollide or torso
}
ReplicatedStorage
:WaitForChild("Remote")
:WaitForChild("Warp")
:WaitForChild("Remotes")
:WaitForChild("Knife")
:FireServer(unpack(args))
end
end)
Comments
No comments yet
Be the first to share your thoughts!