I’m trying to have an anchored part be welded to an unanchored part so the .Touched() event can fire when touching other anchored parts, however this doesn’t work with welds. Are there any alternatives?
When a part is touched, check if the touching part is anchored. If it is, create a weld.
part.Touched:Connect(function(t)
if t:IsAPart() then
if t.Anchored == true then
local weld Instance.new("Weld")
weld.Parent = part
weld.Part0 = part
weld.Part1 = t
end
end
end
If the touching parts are anchored, the touched event doesn’t happen.
Welding an unanchored part makes it treated like an anchored part.
I think you checked the conditional statements wrong, IsA
is a function which detects for a specific Object, not IsAPart()
part.Touched:Connect(function(t)
if t:IsA("Part") and t.Anchored then
local weld = Instance.new("Weld")
weld.Parent = part
weld.Part0 = part
weld.Part1 = t
end
end
You could also use GetTouchingParts()
to detect for the Weld making that way I believe
1 Like