Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clickable part that makes the part unanchor when clicked?

Asked by
Worzr 0
3 years ago

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

Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago

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

0
if u put this in a normal script and not a localscript then this should work ye Pitched_mobile 191 — 3y
Log in to vote
0
Answered by 3 years ago

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

0
the line 11 to 19 is other script I just didnt seperated it bc why not acediamondn123 147 — 3y

Answer this question