I have a moving object and a part that detect if moving object touches
but unfortunately nothing happens.
local function onTouch(hit)
if hit.Name = "HitPart" then -- the moving object
script.Parent.Anchored = false
end
script.Parent.Touched:connect(onTouch)
Instead of if hit.Parent.Name == "HitPart"
you did if hit.Parent.Name = "HitPart"
. It doesn’t actually check the name, instead it sets the name to the string.
it still wont work for some reoson
Also you forgot a then
30chars
Try this:
local function onTouch(hit)
if hit.Parent.Name == "HitPart" then
script.Parent.Anchored = false
end
end
script.Parent.Touched:Connect(onTouch)```
Still wont work the moving object is in a model aswell
The initial code is not complete code, but the headline of this thread is correct. CFrame’ing objects is a mode of movement that is outside of the physics engine, so a touch event may not be fired.
2 Likes
If you absolutely must move an object by cframe, instead of some physics constraint, then you may want to write custom code to check for intersections when moving the cframe parts. You can still use GetTouchingParts() to check to see what is touching.