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 3 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?

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

6 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local clickDetector = Instance.new("ClickDetector")
local part = game.Workspace.Part
part.Parent = clickDetector

script.Parent.MouseClick:Connect(function ()
       part.Anchored = false
end)

This is a easier and simpler method.

0
i meant part.Anchored = false btw! Ponytails2017 83 — 3y
0
fixed Ponytails2017 83 — 3y
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 — 3y
0
okay thanks for the feedback Ponytails2017 83 — 3y
Ad
Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

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

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:

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:

script.Parent.Anchored = false

Hope this helps you.

Log in to vote
0
Answered by
Nozazxe 107
3 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.

local clickDetector = game.Workspace.Part:FindFirstChild:("ClickDetector")
local event = game.ReplicatedStorage.RemoteEvent

clickDetector.MouseClick:Connect(function()
event:FireServer()
end)

then have a script in workspace and put this in.

local event = game.Workspace.RemoteEvent
local part = game.Workspace.Part

event.OnServerEvent:Connect(function()
part.Anchored = false
end)

hope this works!

0
There's no reason to use a RemoteEvent for this. xInfinityBear 1777 — 3y
0
too complicated ,lmao. No need for remoteevents, like infinity bear said Nitrolux200 62 — 3y
0
so? it works. Nozazxe 107 — 3y
Log in to vote
0
Answered by 3 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:

local part = script.Parent --gets the part to be anchored/unanchored
local anchored = true

part.ClickDetector.MouseClick:Connect(function()
    if anchored then --checks if part is anchored
        anchored = false
        part.Anchored = anchored --turns anchored into false
    else --if unanchored then
        anchored = true
        part.Anchored = anchored --turns anchored into true
    end
end)

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 — 3y
0
I recommend to put the script inside CD, that way you don't need to put variables in. Nitrolux200 62 — 3y
Log in to vote
0
Answered by 3 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.

-- Insert Part into Workspace
-- Insert ClickDetector into Part
-- Insert Script into ClickDetector and type the below out

script.Parent.MouseClick:Connect(function()
    script.Parent.Parent.Anchored = false
    script.Parent:Destroy() -- Destroying ClickDetector since part already un-anchored. Remove this line if you want to keep ClickDetector
    print("Works Fine Dude") -- Making sure it works
end)
Log in to vote
0
Answered by 3 years ago

all of these methods work btw

0
most of them skinny_Nikki123 2 — 3y

Answer this question