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.
The easiest solution to your problem are these few steps.
Regular Script
into the part.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
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