Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

11 comments

0

works but i want the whole beam to go from fully opaque gradually up to completely invisible

0

Thank you, I've learned something new! :)

0

@Asworme You're welcome. @SirTotten I will try to find a different solution.

0

Finally edited. View to the bottom of my answer.

0

it tells me "NumberSequence.new(): table of NumberSequenceKeypoints expected."

0

I realized that my new code was jumbled because of typing. I'll fix it.

0

Okay I edited ir again.

0

says the same thing on line 11 (for me its line 29)

0

Crap. I found out that I am calling a nonexisting variable. I am really sorry, will do better. Let me edit again.

0

it works, thanks man

0

Looked everywhere for the proper way to implement a new NumberSequence, thanks for the example.

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()

5 comments

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.

0

Fair point, i'll add a way to use TweenService for Number Sequences

0

Okay. Good luck with that.

0

Okay finished, thanks for telling me

0

No problem.

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

4 comments

0

gives the same arithmetic issue

0

Beams are different from Parts. Their Transparency properties hold different values. Parts hold float values while Beams hold Number Sequences. Read my answer.

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.

0

Transparency can still go above 1, but it remains identical to the maximum value. You got a point there.

This discussion is preserved as it was. New answers, comments, and votes are closed.