Advertisement
Firebirdzz

Example 4.2

Dec 19th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.44 KB | None | 0 0
  1. -- Dive (serverSided)
  2. local replicatedStorage = game:GetService("ReplicatedStorage")
  3. local serverPartsFolder = replicatedStorage.ServerParts
  4. local tool = script.Parent.Parent
  5. local effectFolder = tool.Effects
  6. local effects = effectFolder.Q
  7. local serverParts = serverPartsFolder.Water.Q
  8. local tweenService = game:GetService("TweenService")
  9. local workspaceFolder = workspace:WaitForChild("ServerEffectStorage")
  10.  
  11. characterServer = nil
  12. globalDiveStart = nil
  13. globalDiveBall = nil
  14.  
  15. local function turnInvisible()
  16.     for i,v in pairs(characterServer:GetChildren()) do
  17.         if v:IsA("BasePart") or v:IsA("MeshPart") then
  18.             if v.Name ~= "HumanoidRootPart" then
  19.                 v.Transparency = 1
  20.             end
  21.         end
  22.     end
  23.     for i,v in pairs(characterServer:GetChildren()) do
  24.         if v:IsA("Accessory") then
  25.             v.Handle.Transparency = 1
  26.         end
  27.     end
  28. end
  29.  
  30. local function turnVisible()
  31.     for i,v in pairs(characterServer:GetChildren()) do
  32.         if v:IsA("BasePart") or v:IsA("MeshPart") then
  33.             if v.Name ~= "HumanoidRootPart" then
  34.                 v.Transparency = 0
  35.             end
  36.         end
  37.     end
  38.     for i,v in pairs(characterServer:GetChildren()) do
  39.         if v:IsA("Accessory") then
  40.             v.Handle.Transparency = 0
  41.         end
  42.     end
  43. end
  44.  
  45. effects.RemoteEvents.Press.OnServerEvent:Connect(function(plr, localCFrame)
  46.    
  47.     plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed / 2
  48.    
  49.     print(plr.Name.." is aiming move Q.")
  50.    
  51. end)
  52.  
  53. effects.RemoteEvents.Release.OnServerEvent:Connect(function(plr, globalCFrame, targetCFrame)
  54.     print(plr.Name.." is done aiming move Q. Their current CFrame is:")
  55.     print(globalCFrame)
  56.    
  57.     for _, track in pairs (plr.character.Humanoid:GetPlayingAnimationTracks()) do
  58.         track:Stop()
  59.     end
  60.    
  61.     plr.Character.HumanoidRootPart.Anchored = true
  62.    
  63.     -- Sounds --
  64.     local diveUp = effects:WaitForChild("Sounds"):WaitForChild("Dive up"):Clone()
  65.     diveUp.Parent = workspace
  66.     diveUp.Parent = plr.Character.HumanoidRootPart
  67.     diveUp:Play()
  68.    
  69.     task.delay(.4, function()
  70.         local windEffect = effects:WaitForChild("Sounds"):WaitForChild("Dive Air Sound"):Clone()
  71.         windEffect.Parent = workspace
  72.         windEffect.Parent = plr.Character.HumanoidRootPart
  73.         windEffect:Play()
  74.     end)
  75.    
  76.     task.delay(1, function()
  77.         local splashEffect = effects:WaitForChild("Sounds"):WaitForChild("Splash"):Clone()
  78.         splashEffect.Parent = workspace
  79.         splashEffect.Parent = plr.Character.HumanoidRootPart
  80.         splashEffect:Play()
  81.     end)
  82.    
  83.    
  84.     -- StartPosition --
  85.     local diveStart = serverParts:WaitForChild("DiveStart"):Clone()
  86.     diveStart.Parent = workspace
  87.     diveStart.Parent = effectFolder
  88.     diveStart.CFrame = globalCFrame
  89.     globalDiveStart = diveStart
  90.    
  91.     -- "Player" ball effect --
  92.     local diveBall = serverParts:WaitForChild("DiveBall"):Clone()
  93.     diveBall.Parent = workspace
  94.     diveBall.Parent = effectFolder
  95.     diveBall.CFrame = plr.Character.HumanoidRootPart.CFrame
  96.     globalDiveBall = diveBall
  97.    
  98.    
  99.     --- Dive Script --
  100.     local RunService = game:GetService("RunService")
  101.    
  102.     local function Bezier(t, P0, P1, P2)
  103.         local point = (1-t)^2 * P0 + 2 * (1-t) * t * P1 + t^2 * P2
  104.         return point
  105.     end
  106.    
  107.     local function PerformDive(targetCframe)
  108.         local startPos = plr.Character.HumanoidRootPart.Position
  109.         local controlPoint = (startPos + targetCframe) / 2 + Vector3.new(0, 150, 0)
  110.         local endPos = targetCframe
  111.  
  112.         --
  113.         local duration = 1.1
  114.         local elapsedTime = 0
  115.             local connection
  116.             connection = RunService.Heartbeat:Connect(function(dt)
  117.             elapsedTime = elapsedTime + dt
  118.             local t = elapsedTime / duration
  119.  
  120.             if t > 1 then t = 1 end -- Clamp , nill overshooting
  121.            
  122.             if t >= 1 then
  123.                 connection:Disconnect()
  124.                 --  plr.Character.HumanoidRootPart.Position = targetCFrame.Position + Vector3.new(0,10,0)
  125.                 plr.Character.HumanoidRootPart.Anchored = false
  126.                 plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed * 2
  127.                 --return
  128.             end
  129.            
  130.             if t < 1 then
  131.             -- Calculation/Bezier curve
  132.             local newPosition = Bezier(t, startPos, controlPoint, endPos)
  133.  
  134.                 plr.Character.HumanoidRootPart.CFrame = CFrame.new(newPosition, endPos)
  135.                 if t <.3 then
  136.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(0,0,89.6)
  137.                 elseif t <.4 then
  138.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(.4,0,89.6)
  139.                 elseif t <.45 then
  140.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(.6,0,89.6)
  141.                 elseif t <.5 then
  142.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(.8,0,89.6)
  143.                 elseif t <.55 then
  144.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(.9,0,89.6)
  145.                 elseif t <.6 then
  146.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(1,0,89.6)
  147.                 elseif t <.65 then
  148.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(1.2,0,89.6)
  149.                 elseif t <.7 then
  150.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(1.4,0,89.6)
  151.                 elseif t <.75 then
  152.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(1.6,0,89.6)
  153.                 elseif t <.8 then
  154.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(1.8,0,89.6)
  155.                 elseif t <.85 then
  156.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(2.05,0,89.6)
  157.                 elseif t<.9 then
  158.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(2.3,0,89.6)
  159.                 elseif t>.9 then
  160.                     diveBall.CFrame = CFrame.new(newPosition, endPos) * CFrame.Angles(5,0,89.6)
  161.                 end
  162.             end
  163.         end)
  164.     end
  165.    
  166.     PerformDive(targetCFrame.Position + Vector3.new(0,10,0))
  167.    
  168.     characterServer = plr.Character
  169.     turnInvisible()
  170.    
  171.     task.delay(1, function()
  172.         local endDive = serverParts:WaitForChild("DiveEnd"):Clone()
  173.         endDive.Parent = workspace
  174.         endDive.Parent = effectFolder
  175.         endDive.CFrame = targetCFrame * CFrame.new(0,5,0)
  176.        
  177.         local vortex = serverParts:WaitForChild("Vortex"):Clone()
  178.         vortex.Parent = workspace
  179.         vortex.Parent = effectFolder
  180.         vortex.CFrame = endDive.CFrame
  181.        
  182.         globalDiveBall:Destroy()
  183.        
  184.         wait(1)
  185.        
  186.         for _, particle in pairs (endDive:GetDescendants()) do
  187.             if particle:IsA("ParticleEmitter") then
  188.                 particle.Enabled = false
  189.             end
  190.         end
  191.         for _, particle in pairs (vortex:GetDescendants()) do
  192.             if particle:IsA("ParticleEmitter") then
  193.                 particle.Enabled = false
  194.             end
  195.         end
  196.         wait(3)
  197.         endDive:Destroy()
  198.         vortex:Destroy()
  199.     end)
  200.    
  201.     task.delay(1.5, function()
  202.         turnVisible()
  203.        
  204.         for _, particle in pairs (globalDiveStart:GetDescendants()) do
  205.             if particle:IsA("ParticleEmitter") then
  206.                 particle.Enabled = false
  207.             end
  208.         end
  209.        
  210.     end)
  211. end)
  212.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement