Advertisement
Firebirdzz

Example 4.1

Dec 19th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.60 KB | None | 0 0
  1. -- Dive (clientSided)
  2. local tool = script.Parent.Parent
  3. local player = game.Players.LocalPlayer
  4. local char = player.Character
  5. local hmrp = char.HumanoidRootPart
  6. local character = player.Character
  7. local userInputService = game:GetService("UserInputService")
  8. local isPressingQ = false
  9. local equipped = false
  10. local effects = tool.Effects.Q
  11. local remoteEvents = effects.RemoteEvents
  12.  
  13. local mouse = player:GetMouse()
  14.  
  15. clientTarget = nil
  16. globalCFrame = nil
  17. targetCFrame = nil
  18. globalRangeLimit = nil
  19. globalWeld = nil
  20.  
  21. charDescendantTable = {}
  22.  
  23. -- Config --
  24. local MaxPlaceDistance = 110
  25. --
  26.  
  27. tool.Equipped:Connect(function()
  28.     equipped = true
  29. end)
  30.  
  31. tool.Unequipped:Connect(function()
  32.     equipped = false
  33. end)
  34.  
  35. local function CreateRaycastParams()
  36.     local raycastParams = RaycastParams.new()
  37.    
  38.     raycastParams.FilterDescendantsInstances = {clientTarget, char}
  39.    
  40.     raycastParams.CollisionGroup = "Default"
  41.    
  42.     raycastParams.FilterType = Enum.RaycastFilterType.Exclude
  43.     return raycastParams
  44. end
  45.  
  46. local function getGroundPosition(position)
  47.     local groundRaycastParams = RaycastParams.new()
  48.  
  49.     groundRaycastParams.FilterDescendantsInstances = {char, clientTarget, char:GetDescendants(), workspace:WaitForChild("ServerEffectStorage"):GetDescendants()}
  50.     groundRaycastParams.FilterType = Enum.RaycastFilterType.Exclude
  51.  
  52.     local groundRay = workspace:Raycast(position, Vector3.new(0, -100,0), groundRaycastParams)
  53.    
  54.     if groundRay then
  55.         return groundRay.Position
  56.     else
  57.         return position
  58.     end
  59. end
  60.  
  61.  
  62. local function UpdateTargetCFrame()
  63.     local Origin = hmrp.Position
  64.     local MousePosition = mouse.Hit.p
  65.     local Direction = (MousePosition - Origin).unit
  66.     local raycastParams = CreateRaycastParams()
  67.     local RayCastResult = workspace:Raycast(Origin, Direction * MaxPlaceDistance, raycastParams)
  68.     local TargetPosition
  69.     if RayCastResult then
  70.         TargetPosition = RayCastResult.Position
  71.     else
  72.         TargetPosition = Origin + Direction * MaxPlaceDistance
  73.     end
  74.     TargetPosition = getGroundPosition(TargetPosition)
  75.     clientTarget.Position = TargetPosition
  76. end
  77.  
  78. userInputService.InputBegan:Connect(function(input, gameprocess)
  79.     if gameprocess then return end
  80.     if input.KeyCode == Enum.KeyCode.Q and equipped == true then
  81.  
  82.         print(player.Name.." has pressed Q. It's being held down.")
  83.        
  84.         local localCFrame = character.HumanoidRootPart.CFrame
  85.        
  86.         remoteEvents.Press:FireServer(localCFrame)
  87.        
  88.         --// Creating a client target \\--
  89.         isPressingQ = true
  90.        
  91.         local hipHeight = character.Humanoid.HipHeight
  92.        
  93.         local target = game:GetService("ReplicatedStorage"):WaitForChild("ServerParts"):WaitForChild("Water"):WaitForChild("Q"):WaitForChild("Target"):Clone()
  94.         target.Parent = workspace
  95.         clientTarget = target
  96.        
  97.         local rangeLimit = game:GetService("ReplicatedStorage"):WaitForChild("ServerParts"):WaitForChild("Water"):WaitForChild("Q"):WaitForChild("RangeLimit"):Clone()
  98.         rangeLimit.Parent = workspace
  99.         rangeLimit.CFrame = localCFrame * CFrame.new(0,-hipHeight,0)
  100.         rangeLimit.Parent = char
  101.         globalRangeLimit = rangeLimit
  102.         local weld = Instance.new("WeldConstraint")
  103.         weld.Part0 = rangeLimit
  104.         weld.Part1 = character.HumanoidRootPart
  105.         weld.Parent = char
  106.         globalWeld = weld
  107.        
  108.         -- Get the player ignore list immediately, once. --
  109.         -- Discontinued: now uses CollisionGroup.
  110.        
  111.        
  112.         while isPressingQ == true do
  113.             wait()
  114.             UpdateTargetCFrame()
  115.         end
  116.        
  117.     end
  118. end)
  119.  
  120.  
  121. userInputService.InputEnded:Connect(function(output, gameprocess)
  122.     if gameprocess then return end
  123.     if output.KeyCode == Enum.KeyCode.Q and equipped == true then
  124.        
  125.         print(player.Name.." has stopped pressing Q.")
  126.         isPressingQ = false
  127.        
  128.         globalWeld:Destroy()
  129.        
  130.         local localCFrame = character.HumanoidRootPart.CFrame
  131.         globalCFrame = localCFrame
  132.         targetCFrame = clientTarget.CFrame
  133.  
  134.         remoteEvents.Release:FireServer(globalCFrame,targetCFrame)
  135.        
  136.         task.spawn(function()
  137.             for i = 1,130 do wait()
  138.                 globalRangeLimit.Attachment.Ring.Rate -= 1
  139.             end
  140.             globalRangeLimit:Destroy()
  141.         end)
  142.        
  143.    
  144.        
  145.         -- FoV --
  146.        
  147.         local camera = workspace.CurrentCamera
  148.         local tweenService = game:GetService("TweenService")
  149.  
  150.         local tweenInfo = TweenInfo.new(.55, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true)
  151.         local tweenFov = tweenService:Create(camera, tweenInfo, { FieldOfView = 100 })
  152.  
  153.         tweenFov:Play()
  154.        
  155.         -- FoV II --
  156.        
  157.         tweenFov.Completed:Connect(function()
  158.         local tweenInfo2 = TweenInfo.new(.4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true)
  159.         local tweenFov2 = tweenService:Create(camera, tweenInfo, { FieldOfView = 40 })
  160.  
  161.             tweenFov2:Play()
  162.            
  163.             clientTarget:Destroy()
  164.         end)
  165.     end
  166. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement