the script i been trying is this but i dont understand. would you put it under the click detector or do you put it under the part?
1 | clickDetector.MouseClick:connect( function () |
2 | script.Parent.Part.Anchored = false |
3 | end ) |
1 | local clickDetector = Instance.new( "ClickDetector" ) |
2 | local part = game.Workspace.Part |
3 | part.Parent = clickDetector |
4 |
5 | script.Parent.MouseClick:Connect( function () |
6 | part.Anchored = false |
7 | end ) |
This is a easier and simpler method.
You need to identify a proper function. A basic one would be
1 | function onClicked() |
Put that at the beginning of your script.
There's also another flaw with the script, you have ClickDetector right in the middle, without identifying it. Identifying a ClickDetector would be:
1 | local clickDetector = script.Parent.ClickDetector |
You must also have a part with two aspects. A ClickDetector, and a Script. Do not put the script in the ClickDetector, or the ClickDetector in the script, they go in the part.
That makes it easier to unanchor your part like this:
1 | script.Parent.Anchored = false |
Hope this helps you.
Usally when I use click detectors i fire events with local scripts in starter gui. Create a local script in starter gui, and put a remote event in replicated storage. Your click detector should be under the part, and you can removethe old script you had.
1 | local clickDetector = game.Workspace.Part:FindFirstChild:( "ClickDetector" ) |
2 | local event = game.ReplicatedStorage.RemoteEvent |
3 |
4 | clickDetector.MouseClick:Connect( function () |
5 | event:FireServer() |
6 | end ) |
then have a script in workspace and put this in.
1 | local event = game.Workspace.RemoteEvent |
2 | local part = game.Workspace.Part |
3 |
4 | event.OnServerEvent:Connect( function () |
5 | part.Anchored = false |
6 | end ) |
hope this works!
Make sure the ClickDetector
and the script is under the part you want to be unanchored.
This is how I would do it:
01 | local part = script.Parent --gets the part to be anchored/unanchored |
02 | local anchored = true |
03 |
04 | part.ClickDetector.MouseClick:Connect( function () |
05 | if anchored then --checks if part is anchored |
06 | anchored = false |
07 | part.Anchored = anchored --turns anchored into false |
08 | else --if unanchored then |
09 | anchored = true |
10 | part.Anchored = anchored --turns anchored into true |
11 | end |
12 | end ) |
This way, you can anchor/unanchored the part over and over again. ;)
Simplest way, the rest are fine and good but are way more complicated. This one is easier to understand and learn in general.
1 | -- Insert Part into Workspace |
2 | -- Insert ClickDetector into Part |
3 | -- Insert Script into ClickDetector and type the below out |
4 |
5 | script.Parent.MouseClick:Connect( function () |
6 | script.Parent.Parent.Anchored = false |
7 | script.Parent:Destroy() -- Destroying ClickDetector since part already un-anchored. Remove this line if you want to keep ClickDetector |
8 | print ( "Works Fine Dude" ) -- Making sure it works |
9 | end ) |