Everybody loves explosions. Especially me, in which I grew up playing a game with a lot of them.
However, I am looking to achieve an explosion, which would also end the rest of the script.
What I mean is, to do the following, except in roblox:
specifically stop other scripts in sprite.
for all scripts:
--Explosion code here
for I,v in explosion:GetChildren() do
if v:IsA("Script") then
v.Enabled = false
end
end
for the running script:
--explosion code here
if script.Enabled == true then
script.Enabled = false
return
end
I’m sorry, you don’t understand what I mean.
My code:
local function ExplodeCar(Car)
local Body = Car:WaitForChild("HumanoidRootPart")
local Wheels = Car:WaitForChild("Wheels"):GetChildren()
for i, obj in pairs(Wheels) do
for e, obj2 in pairs(obj:GetChildren()) do
obj2:Destroy()
end
obj.CanCollide = true
obj.Anchored = false
obj.AssemblyLinearVelocity = Vector3.new(math.random(-10, 10), math.random(1, 10), math.random(-3, 3))
end
Body.Anchored = false
Body.CanCollide = true
Body.AssemblyLinearVelocity = Vector3.new(math.random(-10, 10), math.random(1, 10), math.random(-3, 3))
end
local function SetupCar()
script.Parent = script.Parent:WaitForChild("HumanoidRootPart")
script.Parent.Anchored = true
local function SetupWheel(Wheel:MeshPart)
local Pos = Wheel.Position - script.Parent.Position
local WOV = Wheel.Orientation
if Wheel then
Wheel.CanCollide = false
game["Run Service"].PreSimulation:Connect(function()
Wheel.Anchored = true
Wheel.CanCollide = true
local ray = workspace:Raycast(script.Parent.Position, Vector3.new(0, -1, 0) * 100000)
if ray and ray.Distance then
if ray.Distance < 5 then
Wheel.Position = script.Parent.Position + Pos + Vector3.new(0, 5 - ray.Distance, 0) - Vector3.new(script.Parent.AssemblyLinearVelocity.X / script.Parent.Parent.Speed.Value * script.Parent.Parent.Speed.Value / 7.5)
Wheel.Orientation = WOV + Vector3.new(Wheel.Position.X * 35, 0, 0)
else
Wheel.Position = script.Parent.Position + Pos - Vector3.new(script.Parent.AssemblyLinearVelocity.X / script.Parent.Parent.Speed.Value * script.Parent.Parent.Speed.Value / 7.5)
Wheel.Orientation = WOV + Vector3.new(Wheel.Position.X * 35, 0, 0)
end
end
end)
end
end
for i, obj in pairs(script.Parent.Parent.Wheels:GetChildren()) do
SetupWheel(obj)
end
script.Parent.Anchored = false
game["Run Service"].PostSimulation:Connect(function()
script.Parent.Anchored = false
script.Parent.CanCollide = true
script.Parent:WaitForChild("Engine").PlaybackSpeed = (math.abs(script.Parent.AssemblyLinearVelocity.X) / script.Parent.Parent.Speed.Value * 1.5) + 1
script.Parent.CanQuery = false
script.Parent.CanTouch = false
local ray = workspace:Raycast(script.Parent.Position, Vector3.new(0, -1, 0) * 100000)
if ray and ray.Distance then
script.Parent.AssemblyLinearVelocity = Vector3.new(script.Parent.AssemblyLinearVelocity.X, 4 * 5 - ray.Distance * 5, script.Parent.AssemblyLinearVelocity.Z)
end
end)
game.ReplicatedStorage.SendMovement.OnServerEvent:Connect(function(Player, A, D, V)
script.Parent.AssemblyLinearVelocity = Vector3.new((V) * script.Parent.Parent.Speed.Value, script.Parent.AssemblyLinearVelocity.Y, script.Parent.AssemblyLinearVelocity.Z)
end)
local BP = Instance.new("BodyPosition")
BP.Position = script.Parent.Position
BP.Parent = script.Parent
BP.MaxForce = Vector3.new(0, 0, math.huge)
BP.D = 1200
BP.P = 50000000
end
local Car = script.Parent.CarToLoad.Value:Clone()
for i, obj in pairs(Car:GetChildren()) do
obj.Parent = script.Parent
end
Car:Destroy()
SetupCar()
task.wait(3)
ExplodeCar(script.Parent.Parent)