so I have this script for when a model is touched but how do I expand on that to break all welds in the model, once it is touched.
local model = script.Parent
local function onModelTouched(part)
– Filter any instances of the model coming in contact with itself
if part:IsDescendantOf(model) then return end
print(model:GetFullName() … " was touched by " … part:GetFullName())
end
for _, child in pairs(model:GetChildren()) do
if child:IsA(“BasePart”) then
child.Touched:Connect(onModelTouched)
end
end
Format code moment
local model = script.Parent
local function onModelTouched(part)
– Filter any instances of the model coming in contact with itself
if part:IsDescendantOf(model) then return end
print(model:GetFullName() … " was touched by " … part:GetFullName())
end
for _, child in pairs(model:GetChildren()) do
if child:IsA(“BasePart”) then
child.Touched:Connect(onModelTouched)
end
end
I think you can check for every Descendant of the Model whenever it gets touched? Unless if you want the BreakJoints()
function, I can give you a sample if you want
1 Like
well yes, I was going to use the break joints function but I don’t know where to put it.
Gotcha, well I’ll briefly explain it then:
local Part = script.Parent
--So say we make a function that fires whenever it touches something
local function Touched(Hit) --The parameter 'Hit' is what the part hit lol
if Hit.Parent:FindFirstChild("Humanoid") then --Here, we're checking to see if the Hit's Parent (Character's Humanoid) is valid at all
Hit.Parent:BreakJoints() --If we have found a Model, then we can break its joints!
end
end
Part.Touched:Connect(Touched) --We also wanna connect the function as well with the Touched event
If you have any more questions feel free to ask :L
well I’ve found an alternative way of what I want to do but I can’t seem to connect the hit function to a part, rather than the player, so that when this part touches the model, it breaks the joints.
Model = script.Parent
hit = workspace.Invisible
for _,Part in ipairs(Model:GetDescendants()) do
if Part:IsA(“BasePart”) then
Part.Touched:Connect(function(hit)
Model:BreakJoints()
end)
end
end
Replace Model:BreakJoints with
if hit.Parent:IsA(“Model”) then
hit.Parent:BreakJoints()
end
That will break the joints of the hits parent if it’s a model. For example, if a characters arm touches the part the character will break apart.
Written on mobile
1 Like