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

How do I make a script that makes a block's transparency change values?

Asked by
x_Rxd 0
4 years ago

Like I want it to where a block will change values of transparency smoothly, like from 0 to .5 and back

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This isn't a request site, but I'll give you a basic rundown to try and learn from.

local part = workspace.Part -- Define the part
for i = 1,10 do -- Start a loop to fade the part into invisible
    part.Transparency = part.Transparency + .1 -- Everytime the loop runs (10 times total) it will add .1 to the parts transparency
    wait(1) -- Wait 1 second inbetween transparency changes
end -- End first loop
wait(2) -- Wait 2 seconds inbetween
for i = 1,10 do  -- Start another loop to fade the part back visible
    part.Transparency = part.Transparency - .1 -- Same thing as first loop, every time loop runs it will remove .1 from parts transparency
    wait(1) -- Wait another second inbetween changes
end -- End loop

https://developer.roblox.com/en-us/articles/Loops

https://developer.roblox.com/en-us/api-reference/property/BasePart/Transparency

Next time please try and add in more information, and show some code. It's okay if you don't know Lua, and are just trying to learn. However this isn't ScriptingRequesters. If you wish to learn there are many tutorials online and on youtube, just look around.

Edit: As mentioned in the comments below, tween service would probably be the better solution, to avoid mishaps and inconsistency. https://developer.roblox.com/en-us/api-reference/class/TweenService

0
for...do loops are not the way to go if you want a value to change smoothly, as they'll behave strangely if you try to override them. You should definitely use TweenService. SimplyConst 0 — 4y
0
I thought of tween service, however I wasn't sure if OP would even understand. WizyTheNinja 834 — 4y
0
Right, didn't consider that. Sorry. SimplyConst 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You should definitely learn the basics of Lua and do your research before posting a question here. Here's an example of what you're trying to achieve:

local TweenService = game:GetService("TweenService") -- https://developer.roblox.com/en-us/api-reference/class/TweenService
local part = -- {Instance reference} Part reference.
local duration = -- {number} The duration of the change.

-- TweenService:Create creates a new object of class Tween, which essentially controls the playback of your transition. The passed arguments are respectively the Instance to be affected, the properties of the Tween and the properties of the Instance to be affected with their respective values ({property = value}). :Play() plays the Tween that's been generated by the previous method.
TweenService:Create(part, TweenInfo.new(duration), {Transparency = 0.5}):Play() -- Makes the part half transparent.
wait(duration) -- Tweens don't yield, so you'll have to add a wait statement after each TweenService:Create() if you don't want them to override each other.
TweenService:Create(part, TweenInfo.new(duration), {Transparency = 0}):Play() -- Makes the part visible again.

Once again - next time you want to ask a question, please look it up first. Both the DevForum and YouTube have a lot of useful resources for learning Lua. As mentioned in another answer, you should also include a snippet of your code in your question. If you know the basics of Lua but not its features, you should visit https://developer.roblox.com/en-us/api-reference.

Answer this question