Obligatory disclaimer, all of the following has been generated using AI, so forgive my lack of knowledge or terrible terminology when it comes to scripting. Both the model and script are included below.
I’m trying to create a moving sphere that fires a laser with weld-removal properties, however it only seems to work on models that aren’t welded/jointed on anchored pieces. I’ve tried changing their CanTouch/CanCollide settings, re-sized the laser to larger proportions so it could encompass entire buildings, switched from the script spawning its own laser to manually adding one with a modified pivot in its model, all to no effect.
All destructible structures are only held by welds, unanchored, and don’t have any unions in them. I’ve also initially set up a CollisionGroup for the sphere itself not to collide with destructible environment, though this doesn’t seem to be related as reversing it made no difference.
Any and all thoughts would be greatly appreciated.
WeldKnockingIssue.wmv (4.9 MB)
-- WeldKnockerScript
local CollectionService = game:GetService("CollectionService")
local model = script.Parent
local body = model:WaitForChild("Body") -- The sphere base part
-- Weld removal, knockback, and kill
local function onPartTouched(selfPart: BasePart, hitPart: BasePart)
if not hitPart or not hitPart.Parent then
return
end
-- 1) Remove welds from the touched part
for _, weld in ipairs(hitPart:GetDescendants()) do
if weld:IsA("WeldConstraint") or weld:IsA("Weld") then
weld:Destroy()
print("Destroyed weld:", weld.Name, "in", hitPart:GetFullName())
end
end
-- 2) Break joints (e.g. player limbs, unanchored parts)
hitPart:BreakJoints()
-- 3) Apply knockback
local direction = (hitPart.Position - selfPart.Position).Unit
hitPart.AssemblyLinearVelocity = direction * -100
-- 4) Kill the player if it's part of a character
local hitCharacter = hitPart.Parent
local hitHumanoid = hitCharacter:FindFirstChildOfClass("Humanoid")
if hitHumanoid then
hitHumanoid.Health = 0
end
end
-- 1) SPHERE (BODY) Touched
if body:IsA("BasePart") then
body.Touched:Connect(function(hit)
onPartTouched(body, hit)
end)
end
-- 2) LASER PART: Wait for spawn, then connect Touched
model.ChildAdded:Connect(function(child)
-- We assume the laser part is named "LaserPart"
if child:IsA("BasePart") and child.Name == "LaserPart" then
child.Touched:Connect(function(hit)
onPartTouched(child, hit)
end)
end
end)