Advertisement
HowToRoblox

BossClient

Dec 9th, 2022 (edited)
2,854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.90 KB | None | 0 0
  1. local rs = game.ReplicatedStorage:WaitForChild("BossReplicatedStorage")
  2. local re = rs:WaitForChild("RemoteEvent")
  3. local config = require(rs:WaitForChild("Configuration"))
  4. local sounds = rs:WaitForChild("Sounds")
  5. local anims = rs:WaitForChild("Animations")
  6.  
  7. local plr = game.Players.LocalPlayer
  8. local char = script.Parent
  9. local camera = workspace.CurrentCamera
  10.  
  11. local plrGui = plr:WaitForChild("PlayerGui")
  12. local healthBarGui = plrGui:WaitForChild("BossHealthGui")
  13. healthBarGui.Enabled = false
  14.  
  15. local shakeTrauma = 0
  16. local shakeSeed = Random.new():NextNumber()
  17. local shakeIterator = 0
  18. local falloffSpeed = 1.6
  19. local clientStart = tick()
  20. local blurEffect = Instance.new("BlurEffect")
  21. blurEffect.Size = 0
  22. blurEffect.Parent = game.Lighting
  23.  
  24. local ts = game:GetService("TweenService")
  25.  
  26.  
  27. function cameraShake(epicentre:any, duration:number, intensityScale)
  28.     intensityScale = intensityScale or 1
  29.  
  30.     if typeof(epicentre) == "Vector3" then
  31.         shakeTrauma = math.clamp(3/(char.HumanoidRootPart.Position - epicentre).Magnitude, 0, 2) * intensityScale
  32.     else
  33.         shakeTrauma = epicentre * intensityScale
  34.     end
  35.    
  36.     if duration then
  37.         falloffSpeed = shakeTrauma / duration
  38.     else
  39.         falloffSpeed = 1.6
  40.     end
  41.  
  42.     shakeIterator = 0
  43.     shakeSeed = Random.new():NextNumber()
  44. end
  45.  
  46. function tweenModel(model:Model, goalCFrame:CFrame, length:number, style:Enum, direction:Enum)
  47.    
  48.     local cfv = model:FindFirstChildOfClass("CFrameValue")
  49.     if not cfv then
  50.         cfv = Instance.new("CFrameValue")
  51.         cfv.Value = model:GetPivot()
  52.         cfv.Parent = model
  53.        
  54.         cfv:GetPropertyChangedSignal("Value"):Connect(function()
  55.             model:PivotTo(cfv.Value)
  56.         end)
  57.     end
  58.    
  59.     local ti = TweenInfo.new(length or 1, style or Enum.EasingStyle.Linear, direction or Enum.EasingDirection.InOut)
  60.     local tween = ts:Create(cfv, ti, {Value = goalCFrame})
  61.     tween:Play()
  62. end
  63.  
  64.  
  65. re.OnClientEvent:Connect(function(args)
  66.     local instruction = args[1]
  67.    
  68.     if instruction == "TWEEN" then
  69.         tweenModel(args[2], args[3], args[4], args[5], args[6])
  70.        
  71.     elseif instruction == "CAMERA SHAKE" then
  72.         cameraShake(args[2], nil, args[3])
  73.        
  74.        
  75.     elseif instruction == "BOSS INTRO CUTSCENE" then
  76.         camera.CameraType = Enum.CameraType.Scriptable
  77.        
  78.         local boss = args[2]
  79.        
  80.         for _, instruction in pairs(config.IntroCutsceneInstructions) do
  81.             local instructionType = instruction[1]
  82.            
  83.             if instructionType == "WAIT" then
  84.                 task.wait(instruction[2])
  85.                
  86.             elseif instructionType == "CAMERA SHAKE" then
  87.                 cameraShake(instruction[2], instruction[3])
  88.                
  89.             elseif instructionType == "PLAY SOUND" then
  90.                 local sound = sounds:WaitForChild(instruction[2])
  91.                 sound:Play()
  92.                
  93.             elseif instructionType == "PLAY ANIMATION" then
  94.                 local anim = boss.Humanoid.Animator:LoadAnimation(anims:WaitForChild(instruction[2]))
  95.                 anim:Play()
  96.                
  97.             elseif instructionType == "STOP ANIMATION" then
  98.                 local playingAnims = boss.Humanoid:GetPlayingAnimationTracks()
  99.                 for _, anim in pairs(playingAnims) do
  100.                     if anim.Animation.Name == instruction[2] then
  101.                         anim:Stop()
  102.                         break
  103.                     end
  104.                 end
  105.                
  106.             elseif instructionType == "MOVE" then
  107.                 local ti = TweenInfo.new(instruction[3], instruction[4], instruction[5])
  108.                 local tween = ts:Create(camera, ti, {CFrame = instruction[2]})
  109.                 tween:Play()
  110.                 tween.Completed:Wait()
  111.             end
  112.         end
  113.        
  114.         char.HumanoidRootPart.CFrame = config.BossRoom.Spawns.PlayerSpawn.CFrame
  115.         camera.CameraType = Enum.CameraType.Custom
  116.         sounds:WaitForChild("Music"):Play()
  117.        
  118.         local function updateBar()
  119.             healthBarGui.HealthBarFrame.HealthAmount.Text = boss.Humanoid.Health .. "/" .. boss.Humanoid.MaxHealth
  120.             healthBarGui.HealthBarFrame.HealthBar.Size = UDim2.new(boss.Humanoid.Health / boss.Humanoid.MaxHealth, 0, 1, 0)
  121.         end
  122.         updateBar()
  123.         boss.Humanoid.HealthChanged:Connect(updateBar)
  124.        
  125.         healthBarGui.Enabled = true
  126.        
  127.     elseif instruction == "BOSS FIGHT END" then
  128.         sounds.Music:Stop()
  129.         healthBarGui.Enabled = false
  130.     end
  131. end)
  132.  
  133.  
  134. game:GetService("RunService").RenderStepped:Connect(function()
  135.  
  136.     if shakeTrauma > 0 then
  137.        
  138.         local now = tick() - clientStart
  139.         shakeIterator += 1
  140.  
  141.         local shake = (shakeTrauma ^ 2) / 3
  142.  
  143.         local noiseX = (math.noise(shakeIterator, now, shakeSeed)) * shake
  144.         local noiseY = (math.noise(shakeIterator + 1, now, shakeSeed)) * shake
  145.         local noiseZ = (math.noise(shakeIterator + 2 + 1, now, shakeSeed)) * shake
  146.        
  147.         if camera.CameraType == Enum.CameraType.Scriptable then
  148.             camera.CFrame = camera.CFrame * CFrame.Angles(noiseX / 50, noiseY / 50, noiseZ / 50) + Vector3.new(noiseX, noiseY, noiseZ)
  149.         else
  150.             char.Humanoid.CameraOffset = Vector3.new(noiseX, noiseY, noiseZ)
  151.             camera.CFrame = camera.CFrame * CFrame.Angles(noiseX / 50, noiseY / 50, noiseZ / 50)
  152.         end
  153.  
  154.         blurEffect.Size = shake * 5
  155.  
  156.         shakeTrauma = math.clamp(shakeTrauma - falloffSpeed * game:GetService("RunService").Heartbeat:Wait(), 0, 3)
  157.  
  158.     else
  159.         char.Humanoid.CameraOffset = Vector3.new(0, 0, 0)
  160.     end
  161. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement