Destroy part with custom explosion

Hello !
Trying to make a part (custom explosion) that destroy every part when it touches it, or if it’s a player, kill him, Code :

local TS = game:GetService("TweenService")
local TweenI = TweenInfo.new(1.5)
local goalSize = {}
local explosion = script.Parent
goalSize.Size = script.Parent.Size + Vector3.new(250,250,250)
local TweenPlay = TS:Create(explosion, TweenI, goalSize)
TweenPlay:Play()
script.Parent.Explosion:Play()
TweenPlay.Completed:Wait()
script.Parent:Destroy()

script.Parent.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if not hum then
		--	if not string.find(hit.Name, "Safe") then
		game.ReplicatedStorage.Regen:Fire(hit, hit.Parent)
		wait(0.1)
		hit:Destroy()
		--		end
	else
		hum.Health = 0
	end
end)

Script is a server script, Disabled (Enabled via another script)

2 Likes

Precision : The function is on a separated script

Is there a problem with the code?

I tried to debug, and this is the new code :

game.ReplicatedStorage.Regen.Event:Connect(function(part, parent)
	if part:IsA("BasePart") then
		part.Parent = game.ServerStorage.Temporary
		print(part.Parent.Name)
		wait(10)
		part.Parent = parent
		print(part.Parent.Name)
	end
end)

The problem is that it only detect the player, and not the basepart

When connecting events the first thing that gets returned is the LocalPlayer if it’s being fired to the server, you’ll need to add an extra argument at the beginning.

game.ReplicatedStorage.Regen.Event:Connect(function(_, part, parent)
	if part:IsA("BasePart") then
		part.Parent = game.ServerStorage.Temporary
		print(part.Parent.Name)
		wait(10)
		part.Parent = parent
		print(part.Parent.Name)
	end
end)
1 Like

I finished to do it with :GetTouchingParts() thanks for help