-
I am making a sandbox universe like game with planet destruction and more
-
I made a hitbox that when a planet is touched it attracts the other planet into it and explodes
-
I was thinking i can use some kind of radius script or something so it wont be that buggy
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
FIRST SCRIPT
local mainPart = script.Parent
local copy = script:Clone()
script.Parent.Touched:Connect(function(B)
task.wait(0.2)
local tee = Instance.new(“Explosion”)
tee.Parent = game.Workspace
tee.BlastRadius = 0.5
tee.TimeScale = 0.1
tee.Position = B.Position
local otherParts = {B}
if B.Transparency == 0 then
local success, newSubtract = pcall(function()
return mainPart:SubtractAsync(otherParts)
end)
-- If operation succeeds, position it at the same location and parent it to the workspace
if success and newSubtract then
local velocity = Instance.new("BodyVelocity")
velocity.Name = "Sway"
velocity.Parent = newSubtract
local cc = script.Parent.ClickDetector:Clone()
local weld = script.Parent.GravityWeld:Clone()
local h = script.Parent.Highlight:Clone()
local ss = script.Parent.Scriptd:Clone()
local hh = script.Parent.Mars:Clone()
weld.Parent = newSubtract
weld.Part0 = newSubtract
hh.Parent = newSubtract
newSubtract.Name = "Mars"
cc.Parent = newSubtract
h.Parent = newSubtract
ss.Parent = newSubtract
copy.Parent = newSubtract
newSubtract.Position = mainPart.Position
newSubtract.Parent = workspace
newSubtract.UsePartColor = true
script.Parent.Front.Touched:Connect(function()
velocity.MaxForce = Vector3.new(math.huge, 0, 0)
velocity.Velocity = Vector3.new(1, 0, 0)
end)
task.wait(0.1)
end
-- Destroy original parts which remain intact after operation
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end
end
end)
VIDEO PROOF:
SECOND UPDATED SCRIPT
local mainPart = script.Parent
local copy = script:Clone()
script.Parent.Touched:Connect(function(B)
task.wait(0.2)
local tee = Instance.new(“Explosion”)
tee.DestroyJointRadiusPercent = 0
tee.Parent = game.Workspace
tee.BlastRadius = 0.5
tee.TimeScale = 0.1
tee.Position = B.Position
local otherParts = {B}
if B.Transparency == 0 then
local success, newSubtract = pcall(function()
return mainPart:SubtractAsync(otherParts)
end)
-- If operation succeeds, position it at the same location and parent it to the workspace
if success and newSubtract then
local velocity = Instance.new("BodyVelocity")
velocity.Name = "Sway"
velocity.Parent = newSubtract
local cc = script.Parent.ClickDetector:Clone()
local weld = script.Parent.GravityWeld:Clone()
local h = script.Parent.Highlight:Clone()
local ss = script.Parent.Scriptd:Clone()
local hh = script.Parent.Mars:Clone()
local fr = script.Parent.Front:Clone()
fr.Parent = newSubtract
ww.Parent = newSubtract
ww.Part0 = newSubtract
ww.Part1 = fr
weld.Parent = newSubtract
weld.Part0 = newSubtract
hh.Parent = newSubtract
newSubtract.Name = "Mars"
cc.Parent = newSubtract
h.Parent = newSubtract
ss.Parent = newSubtract
copy.Parent = newSubtract
newSubtract.Position = mainPart.Position
newSubtract.Parent = workspace
newSubtract.UsePartColor = true
script.Parent.Front.Touched:Connect(function()
velocity.MaxForce = Vector3.new(math.huge, 0, 0)
velocity.Velocity = Vector3.new(1, 0, 0)
end)
task.wait(0.1)
end
-- Destroy original parts which remain intact after operation
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end
end
end)
VIDEO PROOF:
Both the first and the second scripts have a script that in wich a part called front is touched it generates a body velocity to know in whick way to go (EX: planet A hits the other planet B in the front resulting in planet B backing up)
Gravity Hitbox Script:
script.Parent.Touched:Connect(function(t)
if t.Name == “BasePlate” then
task.wait(0.1)
else
if t.Name == “Gravity” then
task.wait(0.1)
else
if t.Name == “Mars” then
task.wait(0.1)
else
if t.Name == “Front” then
task.wait(0.1)
else
t.BodyVelocity:Destroy()
local c = game.ReplicatedStorage.BodyPosition:Clone()
c.Parent = t
c.Position = script.Parent.Position
end
end
end
end
end)
This gravity script attracts other planets into it, as the first and second script taking actions
it is very buggy, first the planet was exploding like crazy and was multiplying at an infinite rate
and now idk why it does this…