How do I make a light?

How do I make a light using this wires, I made a wire system

image

If wires touch each other the volts move along
If 2 wires stick to each other, then voltage will be divided into 2 and each get equal voltage

Wire script:

local startingbrickcolor = script.Parent.BrickColor

script.Parent.Volt.Changed:Connect(function()
    local partstouching = script.Parent:GetTouchingParts()
    if script.Parent.Volt.Value >= 1 and #partstouching ~= 0 then
        script.Parent.BrickColor = BrickColor.new("Bright blue")
        if #partstouching >= 1 and partstouching[1]:IsA("Part") then
            local voltstogive = script.Parent.Volt.Value/#partstouching
            for i,v in pairs(partstouching) do
                if v:IsA("Part") and v.Name == "Wire" then
                    v.Volt.Value = voltstogive
                end
            end
        end
        wait(0.15)
        script.Parent.Volt.Value = 0
        script.Parent.BrickColor = startingbrickcolor
    end
end)

image

Now I want to make a light, if it gets the volts or if a wire is touching it and in it the volt is changed, how do I make a light?

You will have to use one of the three roblox’s light objects: PointLight, SurfaceLight, SpotLight (SurfaceLight is recommended). You can use the .Changed event of the NumberValue “Volt” and you can adjust the Brightness property of the light. Hope this helps! :grinning_face_with_smiling_eyes:

1 Like

Oki, I made this

script.Parent.Changed:Connect(function()
    local touchparts = script.Parent:GetTouchingParts()
    for i,v in pairs(touchparts) do
        print(v.Name)
        if v:IsA("Part") and v.Name == "Wire" then
            v.Volt.Changed:Connect(function()
                if v.Volt.Value >= 1 then
                    print(v.Volt.Value)
                    script.Parent.Material = Enum.Material.Neon
                    wait(1)
                    script.Parent.Material = Enum.Material.SmoothPlastic
                end
            end)
        end
    end
end)

One more question, do you know why is the light getting only 4 volts? When the starting of wire is sending 15 volts