Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do you unanchored a part when clicked?

Asked by 4 years ago

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?

1clickDetector.MouseClick:connect(function()
2    script.Parent.Part.Anchored = false
3end)

6 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
1local clickDetector = Instance.new("ClickDetector")
2local part = game.Workspace.Part
3part.Parent = clickDetector
4 
5script.Parent.MouseClick:Connect(function ()
6       part.Anchored = false
7end)

This is a easier and simpler method.

0
i meant part.Anchored = false btw! Ponytails2017 83 — 4y
0
fixed Ponytails2017 83 — 4y
0
Good but no need to make variables tbh, just insert the script inside clickdetector and you can get started without inserting any variables Nitrolux200 62 — 4y
0
okay thanks for the feedback Ponytails2017 83 — 4y
Ad
Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
4 years ago

You need to identify a proper function. A basic one would be

1function 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:

1local 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:

1script.Parent.Anchored = false

Hope this helps you.

Log in to vote
0
Answered by
Nozazxe 107
4 years ago

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.

1local clickDetector = game.Workspace.Part:FindFirstChild:("ClickDetector")
2local event = game.ReplicatedStorage.RemoteEvent
3 
4clickDetector.MouseClick:Connect(function()
5event:FireServer()
6end)

then have a script in workspace and put this in.

1local event = game.Workspace.RemoteEvent
2local part = game.Workspace.Part
3 
4event.OnServerEvent:Connect(function()
5part.Anchored = false
6end)

hope this works!

0
There's no reason to use a RemoteEvent for this. xInfinityBear 1777 — 4y
0
too complicated ,lmao. No need for remoteevents, like infinity bear said Nitrolux200 62 — 4y
0
so? it works. Nozazxe 107 — 4y
Log in to vote
0
Answered by 4 years ago

Make sure the ClickDetector and the script is under the part you want to be unanchored.

This is how I would do it:

01local part = script.Parent --gets the part to be anchored/unanchored
02local anchored = true
03 
04part.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
12end)

This way, you can anchor/unanchored the part over and over again. ;)

0
Really good, although i don't know why he would need to anchor it again lool. Nitrolux200 62 — 4y
0
I recommend to put the script inside CD, that way you don't need to put variables in. Nitrolux200 62 — 4y
Log in to vote
0
Answered by 4 years ago

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 
5script.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
9end)
Log in to vote
0
Answered by 4 years ago

all of these methods work btw

0
most of them skinny_Nikki123 2 — 4y

Answer this question