if ExplodeEvent then
Rocket.Touched:Connect(function(TouchPart)
if not IGNORE_LIST[string.lower(TouchPart.Name)] and not TouchPart:IsDescendantOf(Character) then
ExplodeEvent:FireServer(Rocket.Position)
if callFunction == false then
callFunction = true
LocalTouchSound:play()
callFunction = false
end
end
end
)end
end
And I want to make that every part the explosion of the rocket launcher touches, Will disappear after 5 seconds.
Can someone help me please/
it appears that you are using Rocket.Touched, as opposed to Explosion.Hit, which gets parts touched by the rocket, rather than the explosion, furthermore, you are destroying parts in a localscript, which would not replicate to the server
There’s also a server script inside the rocket launcher…
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local EquipSound = Handle:WaitForChild("EquipSound")
local ReloadSound = Handle:WaitForChild("ReloadSound")
local Resources = require(script.Parent:WaitForChild("Resources"))
local RocketCreator = require(Resources:GetResource("RocketCreator"))
local BufferCreator = require(Resources:GetResource("BufferCreator"))
local RemoteEventCreator = require(Resources:GetResource("RemoteEventCreator"))
local Configuration = require(Resources:GetResource("Configuration"))
local ROCKET_RELOAD_TIME = Configuration.ROCKET_RELOAD_TIME
local RocketBuffer = BufferCreator:CreateServerBuffer("RocketBuffer")
local FireRocketEvent = RemoteEventCreator:CreateRemoteEvent("FireRocket")
local CurrentPlayer,CurrentCharacter
local CurrentHandRocket,CurrentRocket
local Equipped = false
local ToolEnabled = true
--Adds a rocket to the buffer.
local function AddBufferRocket()
local NewRocket = RocketCreator:CreateRocket(true)
CurrentRocket = NewRocket
RocketBuffer:AddItem(NewRocket)
end
AddBufferRocket()
--Set up firing the rocket.
FireRocketEvent.OnServerEvent:Connect(function(Player)
if Player == CurrentPlayer and ToolEnabled then
ToolEnabled = false
Tool.Enabled = false
CurrentRocket = RocketBuffer:PopItem() or CurrentRocket
local FiredBy = Instance.new("ObjectValue")
FiredBy.Name = "FiredBy"
FiredBy.Value = Player
FiredBy.Parent = CurrentRocket
wait(ROCKET_RELOAD_TIME)
AddBufferRocket()
ToolEnabled = true
Tool.Enabled = true
end
end)
--Set up equipping and unequipping the tool.
Tool.Equipped:Connect(function()
if not Equipped then
Equipped = true
CurrentCharacter = Tool.Parent
CurrentPlayer = game.Players:GetPlayerFromCharacter(CurrentCharacter)
EquipSound:Play()
--Create the left hand rocket.
local LeftGripAttachment = CurrentCharacter:FindFirstChild("LeftGripAttachment",true)
if LeftGripAttachment then
CurrentHandRocket = RocketCreator:CreateRocket(false)
CurrentHandRocket.Name = "HandRocket"
CurrentHandRocket.Transparency = 1
CurrentHandRocket.Parent = Tool
local Weld = Instance.new("Weld")
Weld.Part0 = LeftGripAttachment.Parent
Weld.Part1 = CurrentHandRocket
Weld.C0 = LeftGripAttachment.CFrame
Weld.C1 = CFrame.Angles(0,math.pi,0)
Weld.Parent = CurrentHandRocket
end
RocketBuffer:SetCurrentPlayer(CurrentPlayer)
end
end)
Tool.Unequipped:Connect(function()
if Equipped then
Equipped = false
CurrentCharacter = nil
CurrentPlayer = nil
EquipSound:Stop()
if CurrentHandRocket then CurrentHandRocket:Destroy() end
RocketBuffer:SetCurrentPlayer()
end
end)
What you could do, rather than listening to touch events if they for whatever reason do not work, is use region3 to collect all the parts in a certain radius once the explosion explodes
untested pseudocode;
function rocketExploded()
local position = rocket.Position
local point1 = position-Vector3.new(5,5,5)
local point2 = position+Vector3.new(5,5,5)
local region = Region3.new(point1,point2)
local parts = workspace:FindPartsInRegion3(region)
for _, part in pairs(parts) do
game:GetService("Debris"):AddItem(part,5)
end
end
It doesn’t really matter with functions unless they are within other functions. I would personally put it as local function rocketExploded() but I know some developers prefer not to.
It seems to work, But very laggy and it makes the parts stuck in the air, then just disappear…
How can I add a delay or wait to that function? (between rocket shots)