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

Decreasing Transparency Over Time.. Why wont this code work?

Asked by 6 years ago
Edited 6 years ago

I am trying to make a Part become completely transparent, over the course of 60 seconds. Wait 7 seconds, and then repeat continuously. Here's what I've Tried:

1) Insert NumberValue into Part (Value =0)

2) Inserted Script into part:

01local transparency = script.Parent.Transparency
02 
03while true do
04 
05    script.Parent.Transparency = transparency.Value
06 
07    for i = 1,transparency.Value do
08 
09    wait(1)
10 
11    transparency.Value = transparency.Value + 0.01666666   --i/60
12 
13    script.Parent.Transparency = transparency.Value
14 
15end
View all 21 lines...

While testing the game, the part does not become more transparent.

Here's an error code that show up: Workspace.Part.Transparency Script:3: attempt to index local 'transparency' (a number value)

I'm new to scripting and would really appreciate some help/feedback. Thank you!

2 answers

Log in to vote
0
Answered by
RAYAN1565 691 Moderation Voter
6 years ago
Edited 6 years ago

You're making it more complicated than it has to be. Just do this instead:

01while true do
02    for i = (1/60), 1, (1/60) do
03        wait(1)
04        script.Parent.Transparency = i
05    end
06    script.Parent.Transparency = 1 --This is to ensure that the transparency gets set equal to 1.
07    wait(7)
08    script.Parent.Transparency = 0
09end
10 
11--[[
12 
13i = (1/60) is that starting value,  1 is the ending value, and 1/60 is how much is added to the previous value.
14 
15I basically set the transparency of the part equal to the variable i. That's all you had to do.
16 
17]]--
Ad
Log in to vote
0
Answered by 6 years ago

your scipt sets a variable AS the transparency it's only changing your variable.

1local tparency = script.Parent
2tparency.Transparency = 1 --THIS WORKS
3 
4local tparency2 = script.Parent.Transparency
5tparency2 = .5 -- This changes the variable

also why are you trying to change a nonexisting value you cant have a number in a number ;(transparency.Value does not work) instead do transparency = (number0

0
transparency = 0 to 1 random number also look for output in the view tab this tells you if theres an error when you play youre game(99% of the time) 129Steve129 7 — 6y

Answer this question