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

how would I gradually increase transparency until the transparency gets to 1?

Asked by 6 years ago
Edited 6 years ago
local Player = game.Players.LocalPlayer
local Character = Player.Character
repeat
        Character.Arm1.ControlStone.Beam.Transparency = Character.Arm1.ControlStone.Beam.Transparency - 0.05
    until Character.Arm1.ControlStone.Beam.Transparency == 1

i tried this and it told me "attempt to perform arithmetic on field 'Transparency' (a userdata value)

3 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Transparency from Unions, MeshParts, and other kinds of geometry are floats while Transparency on Beams and Trails are Number Sequences. To be honest, you can actually set them up manually by clicking on the Transparency property, then clicking the 3-dotted button to its right. Add nodes by clicking anywhere (in this case, lowest on the start and highest on the end) on the graph sequence (that's what I call it). Higher values means less opacity while lower values means less transparency.

If you want to put it in a script, then use the NumberSequence, and NumberSequenceKeypoint as shown here (copy if you want):

local Player = game.Players.LocalPlayer
local Character = Player.Character

numseq = {NumberSequenceKeypoint.new(0,0),NumberSequenceKeypoint.new(1,1)}

NS = NumberSequence.new(numseq)

Character.Arm1.ControlStone.Beam.Transparency = NS

I tried this and it is all fine (tested with Beam instance in Workspace, Script in Workspace.)

Hope this fixed your issue.

EDIT: If you want both sides to fade then try this:

local Player = game.Players.LocalPlayer
local Character = Player.Character

gradual = 140 -- Smoothness of transition. May be performance hungry but idk.

waittime = 0.006 -- Speed of transition. Slower at high values and faster at lower values.

for i = 1, gradual do
  wait(waittime)
  numseq = {NumberSequenceKeypoint.new(0,i/gradual),NumberSequenceKeypoint.new(1,i/gradual)}
 NS = NumberSequence.new(numseq)

   Character.Arm1.ControlStone.Beam.Transparency = NS
end

Again, hope this fixed your issue.

Really sorry for the numerous edits because of mistakes.

0
works but i want the whole beam to go from fully opaque gradually up to completely invisible SirTottenhamcake 22 — 6y
0
Thank you, I've learned something new! :) AswormeDorijan111 531 — 6y
0
@Asworme You're welcome. @SirTotten I will try to find a different solution. Bilinearly 58 — 6y
0
Finally edited. View to the bottom of my answer. Bilinearly 58 — 6y
View all comments (7 more)
0
it tells me "NumberSequence.new(): table of NumberSequenceKeypoints expected." SirTottenhamcake 22 — 6y
0
I realized that my new code was jumbled because of typing. I'll fix it. Bilinearly 58 — 6y
0
Okay I edited ir again. Bilinearly 58 — 6y
0
says the same thing on line 11 (for me its line 29) SirTottenhamcake 22 — 6y
0
Crap. I found out that I am calling a nonexisting variable. I am really sorry, will do better. Let me edit again. Bilinearly 58 — 6y
0
it works, thanks man SirTottenhamcake 22 — 6y
0
Looked everywhere for the proper way to implement a new NumberSequence, thanks for the example. ArtiTicce 0 — 2y
Ad
Log in to vote
0
Answered by
CPF2 406 Moderation Voter
6 years ago
Edited 6 years ago

You can use TweenService for this, TweenService functions like a lerp, but you can also apply EasingStyles and EasingDirections

local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut)
local part = Instance.new('Part')
local goal = {}
goal.Transparency = 1

local tween = game:GetService('TweenService'):Create(part,tweenInfo,goal)

tween:Play()

It also should be noted that you can put more/less info into your TweenInfo if you want, ex.


local infoOne = TweenInfo.new(1) local infoTwo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut, 2, true, 0.5)

For more info on what each argument does, go here.

EDIT: Since you need Number Sequences, you can do something like this.

local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut)
local part -- make this equal to what you want to change the transparency of
local val = Instance.new('NumberValue',script)
val.Value = 0
local goal = {}
goal.Value= 1

local tween = game:GetService('TweenService'):Create(val,tweenInfo,goal)

local function OnChanged()
    part.Transparency = NumberSequence.new(val.Value)
end

val.Changed:Connect(OnChanged)

tween:Play()
0
You'll need Number Sequences, not floats nor integers. TweenService won't work for that because the Veam already has tweening in it with Number Sequence Keypoints. Bilinearly 58 — 6y
0
Fair point, i'll add a way to use TweenService for Number Sequences CPF2 406 — 6y
0
Okay. Good luck with that. Bilinearly 58 — 6y
0
Okay finished, thanks for telling me CPF2 406 — 6y
0
No problem. Bilinearly 58 — 6y
Log in to vote
0
Answered by 6 years ago

You can use a loop for your answer.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

for i=0.05, 20 do

        Character.Arm1.ControlStone.Beam.Transparency = Character.Arm1.ControlStone.Beam.Transparency - i
    wait(0.1)
end
0
gives the same arithmetic issue SirTottenhamcake 22 — 6y
0
Beams are different from Parts. Their Transparency properties hold different values. Parts hold float values while Beams hold Number Sequences. Read my answer. Bilinearly 58 — 6y
0
Also your answer would not work for a part either. There is no Transparency value higher than 1 and you are going to 20 in your loop. User#21908 42 — 6y
0
Transparency can still go above 1, but it remains identical to the maximum value. You got a point there. Bilinearly 58 — 6y

Answer this question