Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do you unanchored a part when clicked?

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

✓ Accepted answer
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.

4 comments

0

i meant part.Anchored = false btw!

0

fixed

0

Good but no need to make variables tbh, just insert the script inside clickdetector and you can get started without inserting any variables

0

okay thanks for the feedback

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.

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!

3 comments

0

There's no reason to use a RemoteEvent for this.

0

too complicated ,lmao. No need for remoteevents, like infinity bear said

0

so? it works.

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. ;)

2 comments

0

Really good, although i don't know why he would need to anchor it again lool.

0

I recommend to put the script inside CD, that way you don't need to put variables in.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.