When you destroy the part, you don’t destroy the explosion. To fix this, parent the Explosion to the part so that when the part is destroyed, all of the children including the Explosion will be destroyed.
this works but because it destroys the part after explosion, explosion is destroyed immediately.
so I tried this but it doesn’t destroyst the part at all
local mouse = game.Players.LocalPlayer:GetMouse()
script.Parent.Activated:Connect(function()
script.Parent.Place:FireServer(mouse.Hit.p)
end)
firing it when tool activated,
boom event
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
if (uis:GetFocusedTextBox()) then
return;
end
if input.KeyCode == Enum.KeyCode.Q then
script.Parent.BOOM:FireServer()
end
end)
Could you try altering the scripts and instead, add a script inside the part and instead of adding a new instance, could you try cloning an already-made part with this script inside it:
(Put this script inside a Part object in ServerStorage)
"where ever the event is located".BOOM.OnServerEvent:Connect(function()
local explosion = Instance.new("Explosion")
explosion.Position = script.Parent.Position
explosion.Parent = game.Workspace
script.Parent:Destroy()
end)
(Change the original script to:)
script.Parent.Place.OnServerEvent:Connect(function(player, mousePosition)
local part = game.ServerStorage:FindFirstChild("Part"):Clone()
part.Position = mousePosition
part.Parent = game.Workspace
end)```
You connect the event every time you place a part and then dont disconnect it.
Try this:
script.Parent.Place.OnServerEvent:Connect(function(player, mousePosition)
local part = Instance.new("Part")
part.Position = mousePosition
part.Parent = game.Workspace
local connection
connection = script.Parent.BOOM.OnServerEvent:Connect(function()
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = game.Workspace
part:Destroy()
connection:Disconnect()
end)
end)
Or you can just put the BOOM event outside of the place event, and then loop through all parts you want to explode:
local partsToExplode = {}
script.Parent.Place.OnServerEvent:Connect(function(player, mousePosition)
local part = Instance.new("Part")
part.Position = mousePosition
part.Parent = game.Workspace
table.insert(partsToExplode, part)
end)
script.Parent.BOOM.OnServerEvent:Connect(function()
for _, part in pairs(partsToExplode) do
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = game.Workspace
part:Destroy()
end
partsToExplode = {}
end)
The second method would probably be better, since you would have less connections