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

How to decrease property values incrementally?

Asked by 5 years ago

Experimenting this time with multiple instances like 'Beam', 'SurfaceGUI', 'TextLabels', and 'PointLight'. Code below works properly, just not sure how to go about using the 'for' loop making it so that each activation (or deactivation) makes the instances fade in or out.

--Setting some variables here and should be alphabetical--

surface = script.Parent.Parent.Surface
root = script.Parent.Parent
base = script.Parent
light = root.Emitter.p1
text0 = surface.G0.T0
text1 = surface.G1.T1
b0 = root.Emitter.b0
b1 = root.Emitter.b1

--Add a debounce here plus some extras--

local isOn = false
local debounce = false -- For later use...

--All the fancy stuff down here--

function holo()
    if isOn == false then
        print("Turning on...")
        wait(2)
        isOn = true
        b0.Enabled = true -- All '.enable' lines self-explanatory, open to future optimization
        light.Enabled = true 
        b1.Enabled = true
        text0.TextStrokeTransparency = 0
        text0.TextTransparency = 0.3
        text1.TextStrokeTransparency = 0
        text1.TextTransparency = 0.3
    elseif isOn == true then
        print("Already on, turning off...")
        wait(3.5)
        isOn = false
        b0.Enabled = false -- All '.enable' lines self-explanatory, open to future optimization
        light.Enabled = false 
        b1.Enabled = false
        text0.TextStrokeTransparency = 1
        text0.TextTransparency = 1
        text1.TextStrokeTransparency = 1
        text1.TextTransparency = 1
        print("Off")
    end
end

script.Parent.ClickDetector.MouseClick:connect(holo)
1
:connect is decaperated use :Connect instead User#23365 30 — 5y
0
I believe this won't change anything as I've been using :connect with no issues but the input is appreciated. PhysEngine 7 — 5y
0
:connect is in fact deprecated, I have also been using :connect with no issues for years now. However, using :Connect is strongly recommended. LisaF854 93 — 5y

1 answer

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
5 years ago
Edited 5 years ago

Here’s a simple loop that should work changing the .Brightness from dim to bright. Its just a for loop where “i” represents the brightness of the part. The 0 is the min brightness and 5 is the max. It is set to increase and decrease from 0-5 and 5-0 in increments of .1. Obviously you can change these values depending on what effect you're trying to achieve. Hope it’s helpful!

local light = script.Parent -- if it’s in the part
while true do
    for i = 0,5,0.1 do
        light.Brightness = i
        wait(1)
    end
    for i = 5,0,-0.1 do --This should be a neg num telling the loop that it is decreasing i.
        light.Brightness = i
        wait(1)
    end
end
0
Correct me if I'm wrong but the while true do loop would be inside the function I specified in my code block? PhysEngine 7 — 5y
Ad

Answer this question