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)
local D = game.Workspace game.Workspace.Radio.MouseButtonClick1:Connect(function() D.Joe2.Anchored = true wait(3) D.Joe2.Anchored = false end)
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:
local model = workspace.Model -- The model we are anchoring workspace.Radio.ClickDetector.MouseClick:Connect(function() --Radio being clicked for _,part in pairs(model:GetChildren()) do --Looping through each object in the model if part:IsA("BasePart") then -- Checking if object is a part part.Anchored = true -- Anchoring the part end end 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:
local workspace = game.Workspace local model = workspace.Model -- your model here workspace.Radio.ClickDetector.MouseClick:Connect(function() for _, object in pairs(model) do if object:IsA("Part") then -- checks if the object is a part object.Anchored = true -- anchoring the model end end 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
local Part = workspace.Part -- Part that needs to be unanchored or anchored local clickDetector = workspace.Button.ClickDetector -- Were click detector is located which is under the button function onMouseClick() -- When mouse clicks print("You clicked me!") -- Prints out I have been clicked to confirm that clicking works 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. end end end clickDetector.MouseClick:connect(onMouseClick) --When mouse clicks
https://i.postimg.cc/ZKHsBHPg/Clicker.png -- Picture https://streamable.com/hry4ti -- Video