Advertisement
HowToRoblox

CannonClient

Jul 2nd, 2022
641
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local uis = game:GetService("UserInputService")
  2.  
  3. local humanoid = script.Parent:WaitForChild("Humanoid")
  4. local camera = workspace.CurrentCamera
  5. local mouse = game.Players.LocalPlayer:GetMouse()
  6.  
  7. local currentCannon = nil
  8.  
  9. local cameraOffset = CFrame.new()
  10.  
  11.  
  12. humanoid.Seated:Connect(function(active, currentSeat)
  13.    
  14.     if active then
  15.         local cannon = currentSeat.Parent.Parent
  16.        
  17.         if cannon.Name == "Cannon" then
  18.             currentCannon = cannon
  19.         end
  20.     else
  21.         currentCannon = nil
  22.     end
  23. end)
  24.  
  25. mouse.Button1Down:Connect(function()
  26.    
  27.     if currentCannon then
  28.         game.ReplicatedStorage.CannonRE:FireServer(currentCannon, "SHOOT", mouse.Hit)
  29.     end
  30. end)
  31.  
  32. game:GetService("RunService").RenderStepped:Connect(function() 
  33.    
  34.     if currentCannon then
  35.         camera.CFrame = currentCannon.Top.Gun.CameraPositionPart.CFrame * cameraOffset
  36.        
  37.         local delta = uis:GetMouseDelta()
  38.        
  39.         game.ReplicatedStorage.CannonRE:FireServer(currentCannon, "MOVE", delta)
  40.        
  41.         camera.CameraType = Enum.CameraType.Scriptable
  42.         uis.MouseBehavior = Enum.MouseBehavior.LockCenter
  43.        
  44.     else
  45.         camera.CameraType = Enum.CameraType.Custom
  46.         uis.MouseBehavior = Enum.MouseBehavior.Default
  47.     end
  48. end)
  49.  
  50. game.ReplicatedStorage.CannonRE.OnClientEvent:Connect(function(ball)
  51.    
  52.     spawn(function()
  53.         camera.FieldOfView = 80
  54.        
  55.         for i = 10, 0, -1 do
  56.             camera.FieldOfView = 70 + i
  57.             wait()
  58.         end
  59.     end)
  60.    
  61.     ball:Destroy()
  62.    
  63.     local newBall = game.ReplicatedStorage.Cannonball:Clone()
  64.     newBall.CFrame = currentCannon.Top.Gun.CannonballPositionPart.CFrame
  65.  
  66.     local bv = Instance.new("BodyVelocity")
  67.     bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  68.     bv.Parent = newBall
  69.  
  70.     local distance = (mouse.Hit.LookVector * 500 - currentCannon.Top.Gun.CannonballPositionPart.Position).Magnitude
  71.     bv.Velocity = mouse.Hit.LookVector * 500
  72.  
  73.     game:GetService("Debris"):AddItem(newBall, 30)
  74.     newBall.Parent = workspace
  75.    
  76.     wait(0.1)
  77.     bv:Destroy()
  78. end)
Advertisement
RAW Paste Data Copied
Advertisement