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

Clickable part that makes the part unanchor when clicked?

I want to click a part that's clickable and have it unanchor, this is the script I have but it don't work, any tips?

local clickDetector = Instance.new("ClickDetector",script.Parent)

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

I am quite new to coding so idk what I did wrong.

3 answers

The easiest solution to your problem are these few steps.

  1. Insert a ClickDetector into your desired part.
  2. Insert a Regular Script into the part.
  3. Type this following code:
script.Parent.ClickDetector.MouseClick:Connect(function() 
       script.Parent.Anchored = false -- Unanchors the parent part
       print("The part has been unanchored!") -- Prints what happened (useful for determining errors)
end)

FIRST OF ALL PLEASE DO A CODE BLOCK

This Is A Code Block!

And This Is Your Code

local clickDetector = Instance.new("ClickDetector",script.Parent)
local part = script.Parent

clickDetector.MouseClick:connect(function() 
part.Anchored = false 
end)

The Code Isnt Tested Soo Yea

1 comment

0

if u put this in a normal script and not a localscript then this should work ye

So I have 2 answers. Here:

Answer 1:

Just add a ClickDetector inside the part then put this code:

script.Parent.ClickDetector.MouseClick:Connect(function() -- Checks if ClickDetector is clicked
	if script.Parent.Anchored ~= false then -- Checks if its already Unanchored
		script.Parent.Anchored = false -- Makes it unanchored if not
	end
end)

It should be ServerSide and the Script is inside the block.

Answer 2:

Put a localscript inside StarterPlayerScripts and add a RemoteEvent somewhere then add a BoolValue that is named whatever you want so we can use that to define if we can make the part unanchored.

-- Local Script --
local player = game.Players.LocalPlayer -- local player
local mouse = player:GetMouse() -- get players mouse

mouse.Button1Down:Connect(function() -- checks if player clicked left mousebutton
	if mouse.Target then -- checks if theres a target
		Event:FireServer(mouse.Target) -- fires the event (Change the Event to define the event ur gonna fire)
	end
end)

-- Script --

Event.OnServerEvent:Connect(function(player, target) -- player is the first parameter (Default), the second one is the parameter we define inside the local script.
	if target:FindFirstChild("yes") then -- checks if it has the BoolValue we added earlier
		if target.Anchored ~= false then -- checks if its Unanchored (why not :))
			target.Anchored = false -- yes
		end
	end
end)

So the 2nd answer is kinda advance but yes hopefully I helped.:) lol

1 comment

0

the line 11 to 19 is other script I just didnt seperated it bc why not

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