Guest User

for pidgey

a guest
Jun 24th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. local Stunned = {Pool = {}}
  2. local mt = {__index = Stunned}
  3.  
  4. function Stunned.new(player, target)
  5.     local humanoid = target:FindFirstChildOfClass("Humanoid")
  6.  
  7.     if not (humanoid) then
  8.         return nil
  9.     end
  10.     local self = {
  11.         old = {
  12.             WalkSpeed = humanoid.WalkSpeed,
  13.             JumpPower = humanoid.JumpPower
  14.         }
  15.         connections = {}
  16.     }
  17.  
  18.     self.player = player
  19.     self.target = target
  20.  
  21.     humanoid.WalkSpeed = 0
  22.     humanoid.JumpPower = 0
  23.  
  24.     self.connections.WalkSpeed = humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
  25.         self.old.WalkSpeed = humanoid.WalkSpeed
  26.  
  27.         print("WalkSpeed", self.old.WalkSpeed)
  28.  
  29.         humanoid.WalkSpeed = 0
  30.     end)
  31.     self.connections.JumpPower = humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function()
  32.         self.old.JumpPower = humanoid.JumpPower
  33.  
  34.         print("JumpPower", self.old.JumpPower)
  35.  
  36.         humanoid.JumpPower = 0
  37.     end)
  38.     Stunned.Pool[self] = true
  39.     setmetatable(self, mt)
  40.     return self
  41. end
  42. function Stunned:Remove()
  43.     self.connections.WalkSpeed:Disconnect()
  44.     self.connections.JumpPower:Disconnect()
  45.     self.target.Humanoid.WalkSpeed = self.old.WalkSpeed
  46.     self.target.Humanoid.JumpPower = self.old.JumpPower
  47.     Stunned.Pool[self] = nil
  48.     self = nil -- lose all references to self so it can be available for garbage collection
  49. end
  50.  
  51. local stunnedInstance = Stunned.new(player, target)
  52. -- ...
  53. stunnedInstance:Remove()
Advertisement
Add Comment
Please, Sign In to add comment