Help with anchor script

title. I made a local script where it should unanchor a part when you click it. I may be wrong but I think local scripts only happen to one player, hence the local name. so here’s the script.
Note: SUS is the part.

local SUS = script.Parent
local function DontFloat()
	SUS.Anchored = false
end

MouseButton1Click:Connect(DontFloat())

Sorry if this question is extremely trivial, I’m very new.
Thank you.

3 Likes

try this

local SUS = script.Parent
local function DontFloat()
	SUS.Anchored = false
end

SUS.MouseButton1Click:Connect(DontFloat)
1 Like

OR THIS

local SUS = script.Parent
local function DontFloat()
SUS.Anchored = false
end

SUS.MouseButton1Click:Connect(DontFloat())
1 Like

Didn’t do anything unfortunately.

Local scripts do not run in workspace.

welp i copy and pasted the code into a normal script. Still didn’t work though. Even if it did work, will the platform fall down only for that player?
Because if it affects the entire server, the level i’m making will be incredibly easy.

local SUS = workspace:FindFirstChild("SUS")
SUS.ClickDetector.MouseButton1Click:Connect(function()
    SUS.Anchored = false
end)

This should be in starterplayer.

Are You Added Clickdedector?

jjkjkjkjkkjkjjkkjkjkjjk 300 chr lmt

where do i put the click detector and the script in starter player? do i put it in starterplayerscripts?

You put it in the part you want to be anchored.
And the script in starterplayerscripts.

just tried that, didn’t work unfortuantely.

i made for you

Untitled Game.rbxl (37.2 KB)

1 Like

Click detectors don’t use MouseButton1Click.

They use MouseClick.

Also, you do not need to use the parameter ‘DontFloat()’ in the code: :Connect(DontFloat()), as just calling ‘DontFloat’ without the brackets runs the function.

Additionally, even if you were using a GUI element and running the MouseButton1Click event, make sure you specify the element using the event, and not calling it on it’s own like you did.

Try this code:

local SUS = script.Parent
local function DontFloat()
	SUS.Anchored = false
end

SUS.ClickDetector.MouseClick:Connect(DontFloat)

Make sure it is a server script (not a local script) placed in the part.

1 Like

i used mouseclick :30 … character limit

1 Like

Nowhere in your response did you say to use MouseClick. Additionally, I am teaching him the correct event used for click detectors, rather than giving him the full project.

In the future, don’t reply with unnecessary comments such as that, as I was helping him identify the error in his code.

1 Like

You Need Add Click Detector to Your part

1t

And Add Localscript to StarterGui

2t

Open Your Localscript Write This

local part = workspace.Part --> RENAME THIS TO YOUR PART NAME

function unanchor()
	part.Anchored = false 
end

part.ClickDetector.MouseClick:Connect(unanchor) --> UNACHORS WHEN PART CLICKED
  1. Create a Regular Script

  2. Set the Scripts RunContext to Client, this will make the script run as a LocalScript, but its usable within the workspace

  3. place it inside workspace

1 Like

Also, might have already been said, but if you un-anchor it with a client script, it will still be anchored to the server, if it was created there.

All your guys’ methods, still didn’t work.

local SUS:BasePart? = workspace:FindFirstChild("SUS") -- where does SUS belong?
local MouseClick = Instance.new("ClickDetector")
MouseClick.Parent = SUS
function Anchor()
	SUS.Anchored = not SUS.Anchored
end
MouseClick.MouseClick:Connect(Anchor)

Localscript inside here:
image

1 Like