Guest User

Code for WindRegionHandler script

a guest
Jul 8th, 2020
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. -- Script by JamzCodin
  2.  
  3. cs = game:GetService("CollectionService")
  4.  
  5. game:GetService("RunService").Heartbeat:Connect(function()
  6.    
  7.     local windintensity = 0
  8.     local direction = Vector3.new(0,0,0)
  9.    
  10.     -- Wind Effects
  11.    
  12.     for i, v in pairs(cs:GetTagged("WindPart")) do
  13.         if v:IsA("BasePart") and v:FindFirstChild("Direction") and v:FindFirstChild("Intensity") then
  14.             windintensity = v:FindFirstChild("Intensity").Value
  15.             direction = v:FindFirstChild("Direction").CFrame.LookVector
  16.            
  17.             local endregion = Vector3.new(v.Position.X + v.Size.X * 0.5, v.Position.Y + v.Size.Y * 0.5, v.Position.Z + v.Size.Z * 0.5)
  18.             local startregion = Vector3.new(v.Position.X - v.Size.X * 0.5, v.Position.Y - v.Size.Y * 0.5, v.Position.Z - v.Size.Z * 0.5)
  19.            
  20.             local region = Region3.new(startregion, endregion)
  21.            
  22.             for i, x in pairs(game.Workspace:FindPartsInRegion3(region)) do
  23.                 if x.Parent:FindFirstChild("Humanoid") and x.Parent:FindFirstChild("HumanoidRootPart") then
  24.                     local addvelocity = direction * windintensity
  25.                    
  26.                     local multiplier = math.abs(x.Parent:FindFirstChild("HumanoidRootPart").Velocity.magnitude)
  27.                    
  28.                     if multiplier > 1 then
  29.                         multiplier = 1
  30.                     end
  31.                    
  32.                     if multiplier < 0.5 then
  33.                         multiplier = 0.5
  34.                     end
  35.                    
  36.                     addvelocity = addvelocity * multiplier
  37.                    
  38.                     x.Parent:FindFirstChild("HumanoidRootPart").Velocity = x.Parent:FindFirstChild("HumanoidRootPart").Velocity + addvelocity
  39.                 end
  40.             end
  41.         end
  42.     end
  43. end)
Advertisement
Add Comment
Please, Sign In to add comment