So I've been trying to un-anchor then anchor a model When you click a button(radio) And the Script doesent work, here is the code.(also I added a click detector to the radio)
1 |
1 | <pre class = "brush: lua" > local D = game.Workspace |
2 |
3 | game.Workspace.Radio.MouseButtonClick 1 :Connect( function () |
4 | D.Joe 2. Anchored = true |
5 | wait( 3 ) |
6 | D.Joe 2. Anchored = false |
7 |
8 | end ) |
9 | </pre> |
1 |
Any ideas on how i can solve this?
Hello!
You seem to be a bit confused on whether or not you can Anchor a model directly. While there is no Anchored property of models, you can loop through each part of the model and Anchor it that way.
Here's an example of what I'm talking about:
01 | local model = workspace.Model -- The model we are anchoring |
02 |
03 | workspace.Radio.ClickDetector.MouseClick:Connect( function () --Radio being clicked |
04 |
05 | for _,part in pairs (model:GetChildren()) do --Looping through each object in the model |
06 | if part:IsA( "BasePart" ) then -- Checking if object is a part |
07 | part.Anchored = true -- Anchoring the part |
08 | end |
09 | end |
10 |
11 | end ) |
Model doesn't have anchored property. You'll need to use for loop or primary part wielding
I also noticed in line 3, game.Workspace.Radio.MouseButtonClick1:Connect(function() is wrong. You need to add .ClickDetector after the Radio
Next one is "MouseButtonClick1" is not an event of ClickDetector. The event is called "MouseClick" ( left click ) or "RightMouseClick" ( right click )
I'll show you for loop usage to anchor a model. You can also learn how to anchor a model using primary part wielding but it's harder to explain.
Basic Code:
01 | local workspace = game.Workspace |
02 | local model = workspace.Model -- your model here |
03 |
04 | workspace.Radio.ClickDetector.MouseClick:Connect( function () |
05 | for _, object in pairs (model) do |
06 | if object:IsA( "Part" ) then -- checks if the object is a part |
07 | object.Anchored = true -- anchoring the model |
08 | end |
09 | end |
10 | end |
Hi, I think you haven't stated in line 1 were the radiobutton is. You just have game.Workspace. It should be game.Workspace."Name of part to be anchored or unanchored".
I have a script below that I have tested and it should work and also pictures and videos on what to do. Also you would have to insert a click detector in the button that triggers the anchoring or unanchoring. The part should also be already anchored for the script below to work, if not then will have to change anchored to false and vice versa at the script below. Thank you
01 | local Part = workspace.Part -- Part that needs to be unanchored or anchored |
02 |
03 |
04 | local clickDetector = workspace.Button.ClickDetector -- Were click detector is located which is under the button |
05 |
06 | function onMouseClick() -- When mouse clicks |
07 | print ( "You clicked me!" ) -- Prints out I have been clicked to confirm that clicking works |
08 | if Part.Anchored = = true then Part.Anchored = false else if Part.Anchored = = false then Part.Anchored = true -- This makes it so that if you press the button the part unanchores and if you press it again it gets anchored again and so on. |
09 | end |
10 | end |
11 | end |
12 |
13 | clickDetector.MouseClick:connect(onMouseClick) --When mouse clicks |
https://i.postimg.cc/ZKHsBHPg/Clicker.png -- Picture https://streamable.com/hry4ti -- Video