Fence = game.Workspace.LMF.Metal
function onTouch(Part)
Fence.Anchored = false
end
Fence.Touched:connect(onTouch)
That up there is what I tried to make,no results...
I even used model scripts to look the differences and possibly fix it,nothing aswell...
If anyone knows,please write a fixed version of mine,I'd be really thankful
PS:The model I try to unanchor is a metal fence>Large Metal Fence-LMF
First, you need to detect when the user touches something that is a child of a model.
1 | game.Workspace.Fence.PART.Touched:connect( function () |
2 |
3 |
4 | end ) |
Now, you need to iterate through the entire model and unanchor it.
1 | game.Workspace.Fence.PART.Touched:connect( function () |
2 |
3 | for i,v in pairs (game.Workspace.Fence:GetChildren()) do |
4 | if v:IsA( "Part" ) then |
5 | v.Anchored = false ; |
6 | end |
7 | end |
8 |
9 | end ) |
You may want to make it detect more than just a Part.
Edit: You might also want to make it recursive!
Models do not have touched events, so I recommend placing a transparent block around the model you want to trigger the function and use that block as the new trigger. Kingdom5 already answered this but I think this might help too.
insert a script inside the part and then type:
1 | script.Parent.touched:connect( function (hit) |
2 | script.parent.Anchored = false |
3 | end ) |