How would i make a tool that can connect a button to a light?

What i would want is for a toll to be able to connect to parts or more and make a button turn them on, like a light turning on when the button is pressed. So kinda like welding a wire to a led and switch.

Heres a image of what the folder looks like.
image
I have tried making the bool change but didnt work, you can see my failed code in the tool script if you scroll down in this fourm.

-- / This is the code inside the button. \ --
local folder = game.Workspace.Test
local button = script.Parent
local light = game.Workspace.Test.Light
local state = false
local deC = Color3.new(0.8, 0, 0)
script.Parent.ClickDetector.MouseClick:Connect(function()
	if state == true then
		print("false")
		state = false
		if light.Connected == true then
			light.Light.Color = Color3.new(0, 0, 0)
		end
		script.Parent.Color = 	deC
	elseif state == false then
		print("True")
		state = true	
		button.Color = Color3.new(0, 0.631373, 0.0745098)
		if light.Connected == true then
			light.Light.Color = Color3.new(1, 0.976471, 0.643137)
		end
	end
end)

I have a tool that creates a rope between the first clicked object and the second clicked object.
Heres an image of that.
image
And heres the code for that tool.

local ropeTool = script.Parent
ropeTool.Activated:Connect(function()
	local player = game:GetService("Players").LocalPlayer
	local mouse = player:GetMouse()

	local firstPart = nil
	local secondPart = nil
	local isFirstPartSelected = false

	local function onPartSelected(part)
		if isFirstPartSelected then
			secondPart = part
			isFirstPartSelected = false
			createRope(firstPart, secondPart)
		else
			firstPart = part
			isFirstPartSelected = true
		end
	end

	mouse.Button1Down:Connect(function()
		local part = mouse.Target
		if part then
			onPartSelected(part)
		end
	end)

end)

function createRope(part1, part2)
	local rope = Instance.new("RopeConstraint")
	local at1 = Instance.new("Attachment")
	local at2 = Instance.new("Attachment")
	at1.Parent = part1
	at2.Parent = part2
	part1.Anchored = true
	part2.Anchored = true
	rope.Attachment0 = at1
	rope.Attachment1 = at2
	rope.Thickness = 0.5
	rope.Length = 0
	rope.Visible = true
	rope.Color = BrickColor.new("Dark stone grey")
	rope.Parent = part1
	local bool1 = part1:FindFirstChild("Connected")
	local bool2 = part2:FindFirstChild("Connected")
	bool1 = true
	bool2 = true
end

return ropeTool

I will try to make you understand if you dont understand :smile:

1 Like