Advertisement
CluelessDev

Player stun script

Jun 26th, 2022
786
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 1. When Triggered player is stun for x ammount of seconds
  2. -- 2. Being stunned means low Jump power, walkspeed etc.
  3. -- 3. The effect will die off after x ammount of secconds
  4.  
  5.  
  6. local Players = game:GetService("Players")
  7.  
  8. local ProximityPrompt = script.Parent.ProximityPrompt
  9. local plrsDebounceList = {}
  10.  
  11.  
  12. Players.PlayerAdded:Connect(function(player)
  13.     plrsDebounceList[player.Name] = false
  14. end)
  15.  
  16. Players.PlayerRemoving:Connect(function(player)
  17.     plrsDebounceList[player.Name] = nil --> remove the player from list when he leaves the game
  18. end)
  19.  
  20.  
  21. -- stun config
  22. local stunDuration = 3
  23.  
  24. local statReductionFactors = {
  25.     WalkSpeed  = 0.1,
  26.     JumpPower  = 0.1,
  27.     JumpHeight = 0.5,
  28. }
  29.  
  30.  
  31.  
  32. ProximityPrompt.Triggered:Connect(function(thePlayer)
  33.     if table.find(plrsDebounceList, thePlayer) then return end --> debounce already stunned players
  34.    
  35.     plrsDebounceList[thePlayer.Name] = true  --> debounce
  36.    
  37.     local humanoid = thePlayer.Character.Humanoid
  38.     local previousValues = {}
  39.    
  40.     -- Cache pre-stun values
  41.     for propName, _ in pairs(statReductionFactors) do
  42.         previousValues[propName] = humanoid[propName]
  43.     end
  44.    
  45.     -- reduce properties current values
  46.     for propName, reductionFactor in pairs(statReductionFactors) do
  47.         humanoid[propName] *= reductionFactor
  48.     end
  49.    
  50.     task.wait(stunDuration)
  51.    
  52.     -- reset modified properties to their previous values
  53.     for propName, prevValue in pairs(previousValues) do
  54.         humanoid[propName] = prevValue
  55.     end
  56.    
  57.     plrsDebounceList[thePlayer.Name] = false       
  58. end)
Advertisement
RAW Paste Data Copied
Advertisement