repeat task.
wait() until game:IsLoaded()
--> Services <--
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--> LocalPlayer Varaibles <--
local player = [Link]
local playerCharacter = [Link]
local playerHumanoidRootPart = playerCharacter:FindFirstChild("HumanoidRootPart")
or playerCharacter:WaitForChild("HumanoidRootPart")
--> LocalPlayer Tools Varaibles <--
local playerTool = nil
local playerToolHandle = nil
--> Function To Handle When LocalPlayer Respawns <--
[Link]:Connect(function(NewCharacter)
playerCharacter = NewCharacter
playerHumanoidRootPart = playerCharacter:FindFirstChild("HumanoidRootPart") or
playerCharacter:WaitForChild("HumanoidRootPart")
end)
--> Function To Get Closest Player <--
local function GetClosestPlayer()
local closestPlayer = nil
local getClosestPlayerDistance = [Link] -- [Link] == inf
for _, Player in pairs(Players:GetPlayers()) do
if Player ~= player and Player and [Link] and
[Link]:FindFirstChild("HumanoidRootPart") and
[Link]:FindFirstChild("Humanoid") and
[Link]:FindFirstChild("Humanoid").Health ~= 0 then
local magnitudeDistance =
([Link]:FindFirstChild("HumanoidRootPart").Position -
[Link]).Magnitude
if magnitudeDistance < getClosestPlayerDistance then
closestPlayer = Player
getClosestPlayerDistance = magnitudeDistance
end
end
end
return closestPlayer
end
--> Sword Reach Event Function <--
[Link]:Connect(function()
--> closestPlayer Varaibles <--
local closestPlayer = GetClosestPlayer()
--> Checks <--
if closestPlayer ~= player and closestPlayer and [Link] and
[Link]:FindFirstChild("Humanoid") and
[Link]:FindFirstChild("Humanoid").Health ~= 0 then
--> closestPlayer Varaibles <--
local closestPlayerCharacter = [Link]
local closestPlayerHumanoidRootPart =
closestPlayerCharacter:FindFirstChild("HumanoidRootPart") or
closestPlayerCharacter:WaitForChild("HumanoidRootPart")
for _, CharacterChild in ipairs(playerCharacter:GetChildren()) do
if CharacterChild and CharacterChild:IsA("Tool") then
for _, ToolHandle in ipairs(CharacterChild:GetChildren()) do
if ToolHandle and ToolHandle:IsA("BasePart") then
if ToolHandle:FindFirstChild("TouchInterest") then
playerTool = CharacterChild
playerToolHandle = ToolHandle
elseif not ToolHandle:FindFirstChild("TouchInterest") then
for _, HandleChild in ipairs(ToolHandle:GetChildren())
do
if HandleChild and HandleChild:IsA("BasePart") then
if HandleChild:FindFirstChild("TouchInterest")
then
playerTool = CharacterChild
playerToolHandle = HandleChild
end
end
end
end
end
end
break
end
end
--> Manipulates Handle Position [ Sword Reach ] <--
if playerTool and playerToolHandle then
[Link]:Connect(function()
if playerTool and playerToolHandle then
--> Manipulates LocalPlayer HumanoidRootPart CFrame To Look At
Closest Player HumanoidRootPart <--
[Link] =
[Link]([Link],
[Link]([Link].X,
[Link].Y, [Link].Z))
[Link] = 0
[Link] = [Link](50, 50, 50)
[Link] =
[Link]
playerTool:Activate()
--[[firetouchinterest(playerToolHandle,
closestPlayerHumanoidRootPart, 1)
firetouchinterest(playerToolHandle,
closestPlayerHumanoidRootPart, 0)]]
end
end)
[Link]:Connect(function()
playerTool = nil
playerToolHandle = nil
end)
end
end
end)