Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Wait for character to properly load
- wait(1)
- --Variables
- local remoteEvent = game.ReplicatedStorage:WaitForChild("RocketLauncherRE")
- local mouse = game.Players.LocalPlayer:GetMouse()
- local camera = workspace.CurrentCamera
- local cameraOffset = 0
- local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local tool = script.Parent
- local config = tool:WaitForChild("Settings")
- local anims = {
- holdAnim = humanoid:LoadAnimation(script:WaitForChild("HoldAnimation")),
- reloadAnim = humanoid:LoadAnimation(script:WaitForChild("ReloadAnimation")),
- shootAnim = humanoid:LoadAnimation(script:WaitForChild("ShootAnimation"))
- }
- local canShoot = false
- --Equipping
- tool.Equipped:Connect(function()
- remoteEvent:FireServer("ConnectM6D", tool)
- character.UpperTorso.RocketLauncherM6D.Part0 = character.UpperTorso
- character.UpperTorso.RocketLauncherM6D.Part1 = tool.BodyAttach
- anims["holdAnim"]:Play()
- canShoot = true
- end)
- --Unequipping
- tool.Unequipped:Connect(function()
- canShoot = false
- remoteEvent:FireServer("DisconnectM6D", tool)
- for i, anim in pairs(anims) do
- anim:Stop()
- end
- end)
- --Shooting
- mouse.Button1Up:Connect(function()
- if canShoot then
- canShoot = false
- anims["shootAnim"]:Play()
- remoteEvent:FireServer("Shoot", tool, mouse.Hit.Position)
- cameraOffset += 3
- --Rocket Jumping - remove these lines if you don't want this feature
- local hrp = character.HumanoidRootPart
- local velocity = -CFrame.new(tool.Rocket.Position, mouse.Hit.Position).LookVector * 100
- hrp.Velocity = velocity
- --
- end
- end)
- --Handle server requests to this client
- remoteEvent.OnClientEvent:Connect(function(instruction, rocketLauncher, cf, serverRocket)
- --Play reload animation after shooting
- if instruction == "reload" and rocketLauncher == tool then
- anims["reloadAnim"]:Play()
- --Handle rocket on clients for smoother motion
- elseif instruction == "shootRocket" then
- local newRocket = rocketLauncher.Rocket:Clone()
- newRocket.Transparency = 0
- newRocket.CFrame = cf
- local speed = rocketLauncher.Settings.RocketSpeed.Value
- local velocity = cf.LookVector * speed
- newRocket.Velocity = velocity
- local trail = Instance.new("Trail")
- trail.FaceCamera = true
- trail.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0, 0.5), NumberSequenceKeypoint.new(1, 1)}
- trail.Lifetime = 0.1
- local atch1 = newRocket.Attachment0:Clone()
- atch1.Position = Vector3.new(0.2, 0, 0)
- atch1.Parent = newRocket
- trail.Attachment0 = newRocket.Attachment0
- trail.Attachment1 = atch1
- trail.Parent = newRocket
- local whoosh = rocketLauncher.BodyAttach.WhooshSound:Clone()
- whoosh.Looped = true
- whoosh.Parent = newRocket
- whoosh:Play()
- newRocket.Parent = workspace.RocketsContainer
- serverRocket.Destroying:Connect(function()
- newRocket:Destroy()
- camera.CameraType = Enum.CameraType.Custom
- end)
- --Remove cooldown when reloading is finished
- elseif instruction == "cooldown" then
- canShoot = true
- end
- end)
- --Event that fires every frame
- game:GetService("RunService").Stepped:Connect(function()
- --Apply recoil to camera
- if tool.Parent == character then
- camera.CFrame = camera.CFrame:Lerp(camera.CFrame * CFrame.Angles(cameraOffset / 30, 0, 0), 0.4)
- cameraOffset = math.clamp(cameraOffset - 0.1, 0, math.huge)
- end
- --Make rockets face the direction they are falling
- for i, rocket in pairs(workspace.RocketsContainer:GetChildren()) do
- rocket.CFrame = CFrame.new(rocket.Position, rocket.Velocity + rocket.Position)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement