So, I have been working on this game recently that uses gears to have people fight each other. I have currently been working on the rocket launcher and it originally worked really well, where the explosion appeared right where the rocket initially hits. after a bit more testing, it just suddenly didn’t? I have no clue what caused it, but the explosions were suddenly appearing behind the rockets.
Here is a video of usage of the rocket launcher, normally it is supposed to deal 30 damage if the rocket itself hits, while the explosion deals 10, making 40 damage on a direct hit.
https://youtu.be/sd6kLbKcU3Q
Here is the server-side code for the rocket launcher:
local tool = script.Parent
exevent = game.ServerScriptService.Event
tool.RemoteEvent.OnServerEvent:Connect(function(player, mousePos)
local dmg = 20
local thingsHit = {}
local explosionHappened = false
local sound = tool.Handle.fire:Clone()
sound.Parent = tool.Handle
sound.TimePosition = 0
sound:Play()
task.delay(5,function()
sound:Destroy()
end)
local rocket = Instance.new("Part")
rocket.Size = Vector3.new(1, 1, 4)
rocket.Color = Color3.fromRGB(130, 0, 0)
rocket.Position = tool.Handle.Position
rocket.CanTouch = false
local function hitMarker(partTouched)
if workspace:GetAttribute("hitboxesVisible", true) then
local hit = Instance.new("Part")
hit.Size = Vector3.new(.5, .5, .5)
hit.Position = rocket.Position
hit.Parent = workspace
hit.CanCollide = false
hit.Anchored = true
hit.BrickColor = BrickColor.new("Bright red")
hit.Material = Enum.Material.Neon
hit.Transparency = .7
task.delay(.1,function()
hit:Destroy()
end)
end
end
local function onTouch(partTouched)
if partTouched.Parent == player.Character or partTouched == tool.Handle then
else
if explosionHappened == false then
rocket:Destroy()
explosionHappened = true
exevent:Fire(rocket.CFrame.Position, 10, 5)
end
if partTouched.Parent:FindFirstChild("Humanoid") then
if partTouched.Parent == tool.Parent then
else
if unpack(thingsHit) == nil then
hitMarker(partTouched)
partTouched.Parent.Humanoid.Health -= 30
else
if table.find(thingsHit, partTouched.Parent.Humanoid) then
else
hitMarker(partTouched)
partTouched.Parent.Humanoid.Health -= 30
end
end
if partTouched.Parent:FindFirstChild("Humanoid") then
table.insert(thingsHit,partTouched.Parent.Humanoid)
end
end
elseif partTouched:FindFirstChild("Humanoid") then
partTouched.Parent.Humanoid.Health -= 30
end
end
end
rocket.CFrame = CFrame.new(rocket.CFrame.Position, mousePos)*CFrame.fromEulerAngles(0,0,0)
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = rocket.CFrame.lookVector * 90
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Parent = rocket
rocket.Touched:Connect(onTouch)
task.delay(.1,function()
rocket.CanTouch = true
end)
rocket.CanCollide = true
rocket.Parent = workspace
rocket:SetNetworkOwner(player)
rocket.CanCollide = false
wait(5)
rocket:Destroy()
end)
And here is the explosion’s code (this script is under a bindable event because i wanted to make the explosion system reusable in the cade i want to make something else explode):
local be = script.Parent
local audio = script.explode
local function onEvent(Pos, Dmg, Rad)
local timer = 10
local thingsHit = {}
local explosion = Instance.new("Part")
explosion.Position = Pos
explosion.Parent = workspace
explosion.Transparency = .65
explosion.Color = Color3.fromRGB(255, 72, 0)
explosion.Size = Vector3.new(Rad*2,Rad*2,Rad*2)
explosion.Anchored = true
explosion.CanCollide = false
local function onTouch(partTouched)
if timer > 6 then
if partTouched.Parent:FindFirstChild("Humanoid") then
if unpack(thingsHit) == nil then
partTouched.Parent.Humanoid.Health -= 10
else
if table.find(thingsHit, partTouched.Parent.Humanoid) then
--print("already there buckaroo")
else
partTouched.Parent.Humanoid.Health -= 10
end
end
if partTouched.Parent:FindFirstChild("Humanoid") then
table.insert(thingsHit,partTouched.Parent.Humanoid)
end
elseif partTouched:FindFirstChild("Humanoid") then
partTouched.Parent.Humanoid.Health -= 10
end
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = (explosion.Position - partTouched.Position) * -20
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Parent = partTouched
task.delay(.1,function()
bodyVelocity:Destroy()
end)
end
end
explosion.Position = Pos
local audioClone = audio:Clone()
audioClone.Parent = explosion
--audioClone.PlaybackSpeed = math.random(0.9,1.1)
audioClone:Play()
explosion.Touched:Connect(onTouch)
while timer > 6 do
wait(.1)
explosion.Size /= Vector3.new(1.6,1.6,1.6)
timer -= 1
end
explosion.CanTouch = false
explosion.Transparency = 1
wait(2)
explosion:Destroy()
end
be.Event:Connect(onEvent)
Please excuse the horrendous way my code looks, roblox studio is confusing and ive been figuring out how to use it by just searching stuff up online.
Thank you!