I'm trying to make a button magnet that will attach a magnet when the button is clicked, and dettach it when it's clicked again. If you can figure out how to form it into an on/off button model rather than a all-purpose-button model, that'd work as well.
~~Button script:
local CD = script.Parent.ClickDetector
local Crane = script.Parent.Parent.Parent
function doit()
Crane.Magnet.turnOff.Value = true
end
CD.MouseClick:connect(doit)
~~Magnet script:
local Base = script.Parent
local Stuck = false
local turnOff = Base.turnOff
deBounce = false
while true do
if turnOff.Value = false then
script.Parent.BodyPosition.position = script.Parent.Parent.mag2.Position
local Stuck = true
turnOff.Changed:connect(unStick)
wait(.1)
local Stuck = false
end
~~The magnet IS named "Magnet" and there is a BodyPositioninside it as well as a turnOff value. |