Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Stunned = {Pool = {}}
- local mt = {__index = Stunned}
- function Stunned.new(player, target)
- local humanoid = target:FindFirstChildOfClass("Humanoid")
- if not (humanoid) then
- return nil
- end
- local self = {
- old = {
- WalkSpeed = humanoid.WalkSpeed,
- JumpPower = humanoid.JumpPower
- }
- connections = {}
- }
- self.player = player
- self.target = target
- humanoid.WalkSpeed = 0
- humanoid.JumpPower = 0
- self.connections.WalkSpeed = humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
- self.old.WalkSpeed = humanoid.WalkSpeed
- print("WalkSpeed", self.old.WalkSpeed)
- humanoid.WalkSpeed = 0
- end)
- self.connections.JumpPower = humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function()
- self.old.JumpPower = humanoid.JumpPower
- print("JumpPower", self.old.JumpPower)
- humanoid.JumpPower = 0
- end)
- Stunned.Pool[self] = true
- setmetatable(self, mt)
- return self
- end
- function Stunned:Remove()
- self.connections.WalkSpeed:Disconnect()
- self.connections.JumpPower:Disconnect()
- self.target.Humanoid.WalkSpeed = self.old.WalkSpeed
- self.target.Humanoid.JumpPower = self.old.JumpPower
- Stunned.Pool[self] = nil
- self = nil -- lose all references to self so it can be available for garbage collection
- end
- local stunnedInstance = Stunned.new(player, target)
- -- ...
- stunnedInstance:Remove()
Advertisement
Add Comment
Please, Sign In to add comment