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

Iterating specific values through a variable wont work here?

Asked by 8 years ago

I've had a similar issue assigning variables to properties in lighting, where the only way to change the values in the lighting folder are to go through the entire hierarchy. in this code, working with a GUI and text label properties, I have the same problem:

plr = game.Players.LocalPlayer
Start = true
Cheese = 0.1

TextTrans = plr.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency
TextBorderTrans = plr.PlayerGui.ScreenGui.Frame.TextLabel.TextStrokeTransparency

function Study()

    if Start == true then
        Start = false

    for i = 0, 1, 0.1 do
    wait(1)
    plr.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency = i
     plr.PlayerGui.ScreenGui.Frame.TextLabel.TextStrokeTransparency =  i

--TextTrans = i
--TextBorderTrans = I  <<this is what I'd rather use, but it wont work unless I do it the way I have above.


    end 
    end
end

game.Workspace.PAT.Touched:connect(Study)

am I defining the variables wrong, making another mistake, or is it not possible to use variables in this way? I've tested the values and they aren't nil, they hold number values like they should- but I cant seem to change them using any loop/iterator unless I go down through the game to them specifically.

1
You want to make a variable to access the object not get the value e.g (geting the object) local txtLable = plr.PlayerGui.ScreenGui.Frame.TextLabel Then use txtLable.TextTransparency = i User#5423 17 — 8y
0
Not this, plr.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency <-- returns the value not the object e.g. 0.5 will be stored User#5423 17 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Variables are values
Oh, hi... Dave.

Values like Transparency and such are literally just numbers. Numbers. Full-stop. They don't know where they came from, they don't care where they came from. If you try and set it to a variable, and you change the variable, you did exactly that - You changed the variable. Now, if you set the Object to a variable, and then you change its Transparency, then you're changing the transparency.

plr = game.Players.LocalPlayer
Start = true
Cheese = 0.1

Text = plr.PlayerGui.ScreenGui.Frame.TextLabel

function Study()

    if Start == true then
        Start = false

    for i = 0, 1, 0.1 do
    wait(1)
    Text.TextTransparency = i
    Text.TextStrokeTransparency =  i
    end 
    end
end

game.Workspace.PAT.Touched:connect(Study)
Simples.
0
oh I see my mistake! thanks for the answer. ProgramsMan 100 — 8y
Ad

Answer this question