Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tweenService = game:GetService("TweenService")
- local remoteEvent = game.ReplicatedStorage:WaitForChild("RocketLauncherRE")
- local cooldown = {}
- --Create container for rockets
- local rocketsContainer = Instance.new("Folder")
- rocketsContainer.Name = "RocketsContainer"
- rocketsContainer.Parent = workspace
- --Create connection when character spawns
- game.Players.PlayerAdded:Connect(function(player)
- player.CharacterAdded:Connect(function(character)
- local motor6d = Instance.new("Motor6D")
- motor6d.Name = "RocketLauncherM6D"
- motor6d.Part0 = character.UpperTorso
- motor6d.Parent = character.UpperTorso
- end)
- end)
- --Handle client requests for gun
- remoteEvent.OnServerEvent:Connect(function(player, instruction, rocketLauncher, mousePos)
- if player.Character and rocketLauncher and rocketLauncher.Parent == player.Character then
- --Connect gun to character's torso when equipped
- if instruction == "ConnectM6D" then
- player.Character.UpperTorso.RocketLauncherM6D.Part1 = rocketLauncher.BodyAttach
- if not rocketLauncher.Rocket:FindFirstChild("Attachment0") then
- local atch0 = Instance.new("Attachment")
- atch0.Name = "Attachment0"
- atch0.Parent = rocketLauncher.Rocket
- end
- --Disconnect gun from character's torso when unequipped
- elseif instruction == "DisconnectM6D" then
- player.Character.UpperTorso.RocketLauncherM6D.Part1 = nil
- --Fire a rocket when player clicks
- elseif instruction == "Shoot" then
- if not cooldown[player] then
- cooldown[player] = true
- rocketLauncher.Rocket.Transparency = 1
- local newRocket = rocketLauncher.Rocket:Clone()
- local cf = CFrame.new(newRocket.Position, mousePos)
- newRocket.CFrame = cf
- local speed = rocketLauncher.Settings.RocketSpeed.Value
- local velocity = cf.LookVector * speed
- newRocket.Velocity = velocity
- rocketLauncher.BodyAttach.ShootSound:Play()
- newRocket.Touched:Connect(function(hit)
- local explosionPos = newRocket.Position
- if not hit:IsDescendantOf(player.Character) then
- local explosionSound = rocketLauncher.BodyAttach.ExplosionSound:Clone()
- newRocket:Destroy()
- local explosion = Instance.new("Explosion")
- explosion.Position = explosionPos
- explosion.Parent = workspace
- local atch = Instance.new("Attachment")
- atch.WorldPosition = explosionPos
- explosionSound.Parent = atch
- atch.Parent = workspace.Terrain
- explosionSound:Play()
- explosionSound.Stopped:Connect(function()
- atch:Destroy()
- end)
- end
- end)
- newRocket.Parent = workspace
- remoteEvent:FireAllClients("shootRocket", rocketLauncher, cf, newRocket)
- remoteEvent:FireClient(player, "reload", rocketLauncher)
- wait(0.5)
- rocketLauncher.Rocket.Transparency = 0
- wait(0.3)
- rocketLauncher.BodyAttach.ReloadSound:Play()
- wait(rocketLauncher.Settings.ReloadTime.Value - 0.5 - 0.3)
- cooldown[player] = nil
- remoteEvent:FireClient(player, "cooldown")
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement