Advertisement
Toxicator1

findPlayerHumanoid

Jan 9th, 2021
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. -- Taken from default character scripts: "StarterPlayer" -> "PlayerModule" -> "ControlModule" -> "ClickToMoveController"
  2. local humanoidCache = {}
  3. local function findPlayerHumanoid(player)
  4.     local character = player and player.Character
  5.     if character then
  6.         local resultHumanoid = humanoidCache[player]
  7.         if resultHumanoid and resultHumanoid.Parent == character then
  8.             return resultHumanoid
  9.         else
  10.             humanoidCache[player] = nil -- Bust Old Cache
  11.             local humanoid = character:FindFirstChildOfClass("Humanoid")
  12.             if humanoid then
  13.                 humanoidCache[player] = humanoid
  14.             end
  15.             return humanoid
  16.         end
  17.     end
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement