HellO! I’m StarJ3M and I’m trying to make a game cald Ro-Fighters!
I’m currently making weapons, and for some reason my rocket launcher script wont work, I’m trying to make it so that wherever the players mouse is, a projectile will shoot out of the launcher and when it hits something then a sound would play and also a particle will get enabled.
-- Variables
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local Projectile = ReplicatedStorage:WaitForChild("Parts"):WaitForChild("Projectile")
local BlastParticle = ReplicatedStorage:WaitForChild("Particles"):WaitForChild("BlastEffect")
local Debounce = false
local Cooldown = 7
local mouse = player:GetMouse()
local FireSound = script.Parent.Handle:WaitForChild("Fire")
local ExplosionSound = script.Parent.Handle:WaitForChild("Boom")
-- Configure
local con = {
rocketSpeed = nil;
damage = function() return math.random(10, 25) end
}
-- Rocket Shot
script.Parent.Activated:Connect(function()
if not Debounce then
local mousePosition = mouse.Hit
Debounce = true
FireSound:Play()
local ProjectileClone = Projectile:Clone()
ProjectileClone.Name = "Projectile"
ProjectileClone.Parent = game.Workspace
ProjectileClone.Position = script.Parent.FirePart.Position
ProjectileClone.Oreintation = ProjectileClone.Oreintation * mousePosition.LookVector
local BodyMover = Instance.new("BodyForce")
BodyMover.Name = "BodyForce"
BodyMover.Parent = ProjectileClone
BodyMover.Force = Vector3.new(0,20,0)
for i = 1, 500 do
ProjectileClone.AssemblyLinearVelocity = Vector3.new(mousePosition)
end
local function ProjectileBlast()
local Explosion = Instance.new("Explosion")
Explosion.Name = "Explosion"
Explosion.Parent = ProjectileClone
Explosion.Position = ProjectileClone.Position
local ExplosionSoundClone = ExplosionSound:Clone()
ExplosionSoundClone.Name = "ExplosionSound"
ExplosionSoundClone.Parent = ProjectileClone
local BlastEffectClone = BlastParticle:Clone()
BlastEffectClone.Name = "Blast"
BlastEffectClone.Parent = ProjectileClone
ExplosionSoundClone:Play()
BlastEffectClone.Enabled = true
wait(0.5)
BlastEffectClone.Enabled = false
delay(1)
delay(3)
Explosion:Destroy()
Debris:AddItem(
ProjectileClone,
0
)
end
ProjectileClone.Touched:Connect(ProjectileBlast)
wait(Cooldown)
Debounce = false
end
end)