Basically, there is a folder called “Geometry” that holds all the bomb models. Each bomb model has an ExplosionSphere part that is visible, an ExplosionHitbox part that is invisible and slightly smaller than the ExplosionSphere, a BombHitbox part that is invisible, a few BombGeometry parts that aren’t affected by the script, and an ObjectValue named “_Explosion”.
The script worked while in a normal script, but I only want bombs to explode and kill a player when THAT player touches it. The player that touches it should also be the only person who can see the explosion, meaning the bomb would still be intact for those who didn’t trigger it. On top of that, I wanted to make a function that could be called at any time that would explode a certain bomb without anyone touching it, and would explode for all players. Any players touching the ExplosionHitbox from that bomb would still be killed. It is a complicated thing but I’m sure it can be done because it worked in a normal script. How would I make this work in a LocalScript?
local function ExplodeObject(ExplosionSphere, ExplosionHitbox, Debounce, Touched)
if Debounce.Value == false then
Debounce.Value = true
local TweenGrow = TS:Create(ExplosionSphere, TweenInfo.new(0.15, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = Vector3.new(15, 15, 15)})
local TweenShrink = TS:Create(ExplosionSphere, TweenInfo.new(0.15, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {Size = Vector3.new(3, 3, 3), Transparency = 1})
local HitboxTweenGrow = TS:Create(ExplosionHitbox, TweenInfo.new(0.15, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = Vector3.new(13, 13, 13)})
TweenGrow:Play()
HitboxTweenGrow:Play()
TweenGrow.Completed:Connect(function()
for i, part in pairs(ExplosionSphere.Parent:GetDescendants()) do
if part:IsA("BasePart") and part.Name ~= "ExplosionSphere" and part.Name ~= "ExplosionHitbox" then
part:Destroy()
end
end
if Touched == false then
ExplosionHitbox.Touched:Connect(function(Touched2)
if Touched2.Name == "Torso" then
Touched2:Destroy()
end
end)
else
Touched:Destroy()
end
TweenShrink:Play()
ExplosionHitbox:Destroy()
end)
TweenShrink.Completed:Connect(function()
ExplosionSphere:Destroy()
end)
end
end
for i, thing in ipairs(Geometry:GetDescendants()) do
if thing:IsA("Model") and thing:FindFirstChild("_Explosion") then
local ExplosionSphere = thing:FindFirstChild("ExplosionSphere")
local ExplosionHitbox = ExplosionSphere:FindFirstChild("ExplosionHitbox")
local Debounce = Instance.new("BoolValue", thing)
Debounce.Name = "Debounce"
Debounce.Value = false
thing:FindFirstChild("BombHitbox").Touched:Connect(function(Touched)
if Touched.Name == "Torso" then
ExplodeObject(ExplosionSphere, ExplosionHitbox, Debounce, Touched)
end
end)
end
end
task.wait(5)
spawn(ExplodeObject(Geometry.TestBombModel.ExplosionSphere, Geometry.TestBombModel.ExplosionSphere.ExplosionHitbox, Geometry.TestBombModel.Debounce, false))