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

sooooo i accidently made a lag script and i need to make a smooth transparency brick?

Asked by 5 years ago

the title explains it all it times out the game, also dont test this it WILL crash yur computer

function touch()
    while true do
    for i = 1, 100 do
    if script.Parent.Transparency + 0.1 then
        script.Parent.CanCollide = false
        if script.Parent.Transparency == 0 then
            for i = 1, 100 do
                if script.Parent.Transparency - 0.1 then
                    script.Parent.CanCollide = true
                    if script.Parent.Transparency == 1 then
                        wait(1)
                    end
                end
            end
        end


end
end
end
end 
script.Parent.Touched:Connect(touch)
0
._. Man, I don't even wanna ask about this mess. greatneil80 2647 — 5y

2 answers

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

I'm assuming that you need a brick that changes its transparency from 0 to 1. (I am not too sure what is the value for opaque and transparent.)

Also, I assume that there is no wait in the for i and while true do loop.

So here is the script, I assume.

function touch()

for i = 1,100 do
    script.Parent.Transparency = script.Parent.Transparency - 0.01
    wait(0.05)
end

If you want CanCollide to be turned off, you can add it before the loop. :>

0
omg i am very new to FOr Loops and stuff so i just tried to make iit lol Vortex_Vasne 89 — 5y
0
I mean experimenting is the best way to learn and memorise for me. FadedJayden_Dev 118 — 5y
0
Also, accept my answer? FadedJayden_Dev 118 — 5y
Ad
Log in to vote
0
Answered by
c0nc3rt 61
5 years ago
Edited 5 years ago

The loop seem not good at all, you should add wait(5) to anti-lag.

function touch()
    while true do
    for i = 1, 100 do
    if script.Parent.Transparency + 0.1 then
        script.Parent.CanCollide = false
        if script.Parent.Transparency == 0 then
            for i = 1, 100 do
                if script.Parent.Transparency - 0.1 then
                    script.Parent.CanCollide = true
                    if script.Parent.Transparency == 1 then
                        wait(1)
                    end
                end
            end
        end


end
end
wait(5)
end
end 
script.Parent.Touched:Connect(touch)

That's all.

Answer this question