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

How do i make a part go from transparent to non-transparent in a certain time?

Asked by 3 years ago

So im trying to make a block like in shadow run, where if you click it the transparency will go to 1 after 1-2.5 seconds. Can someone pls help me? Im having no errors but the script just doesnt work.

The script:

CD = script.Parent
P = CD.Parent
P.Transparency = 0
function onMouseClick() 
    P.Transparency = 0.9
    local value = P.Transparency
    local number = 0.1

    repeat
        value += number
        task.wait(0.5)
    until value == 0
end

CD.MouseClick:Connect(onMouseClick())

1 answer

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

local value = P.Transparency You're setting a number variable of the property instead of changing it. Doing it like this would only save the transparency but can't be modified to actually change the part's transparency. Try doing it this way.

for i = 0, 1 do -- You can use the repeat method if you want, it probably works the same way as this one.
    P.Transparency += i
    task.wait(0.5)
end

Or you can use TweenService.

DevHub: TweenService

Ad

Answer this question