Advertisement
HowToRoblox

ForcefieldHandler

Apr 26th, 2022
2,700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. local tweenService = game:GetService("TweenService")
  2.  
  3.  
  4. for i, descendant in pairs(workspace:GetDescendants()) do
  5.    
  6.     if descendant.Name == "Forcefield" then
  7.        
  8.         local hrps = {}
  9.        
  10.         descendant.Touched:Connect(function(part)
  11.            
  12.             if part.Name == "HumanoidRootPart" and not hrps[part] then
  13.                
  14.                 hrps[part] = true
  15.                
  16.                
  17.                 local pos = part.Position
  18.                
  19.                 local particlePart = script.ParticlePart:Clone()
  20.                 particlePart.CFrame = CFrame.new(pos, part.Velocity * 100)
  21.                
  22.                 particlePart.Parent = workspace
  23.                
  24.                 particlePart.Sound:Play()
  25.                
  26.                
  27.                 local pulse = script.Pulse:Clone()
  28.                 pulse.Size = Vector3.new(0, 0, 0)
  29.                 pulse.CFrame = particlePart.CFrame
  30.                
  31.                 pulse.Parent = workspace
  32.                
  33.                 local tweenInfo = TweenInfo.new(0.7, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
  34.                
  35.                 tweenService:Create(pulse, tweenInfo, {Size = Vector3.new(14.848, 14.848, 0.015)}):Play()
  36.                 tweenService:Create(pulse.Decal1, tweenInfo, {Transparency = 1}):Play()
  37.                 tweenService:Create(pulse.Decal2, tweenInfo, {Transparency = 1}):Play()
  38.                 tweenService:Create(pulse.Light, tweenInfo, {Brightness = 0}):Play()
  39.                
  40.                
  41.                 local bv = Instance.new("BodyVelocity", part)
  42.  
  43.                 bv.Velocity = -part.Velocity * 3
  44.                
  45.                 bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  46.                
  47.                
  48.                 wait(0.3)
  49.                
  50.                 bv:Destroy()
  51.                
  52.                 hrps[part] = nil
  53.                
  54.                 particlePart.ParticleEmitter.Enabled = false
  55.                 particlePart.Sound.Stopped:Wait()
  56.                
  57.                 particlePart:Destroy()
  58.                
  59.                 wait(0.4)
  60.                 pulse:Destroy()
  61.             end
  62.         end)
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement