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

why doesnt my script that is supposed to make a block fade work? [Solved]

Asked by 4 years ago
Edited 4 years ago

so im making an obby and im making a script for a fading part. i thought it would work but it doesnt and now i have no idea how to get it to work.

(fade is an IntValue)

local fade = script.Parent.fade
local fadeAmount = 0.05
local fadeTime = 0.5
local part = script.Parent

part.Touched:Connect(function(hit)
    while true do
        wait(fadeTime)
        fade.Value = fade.Value + fadeAmount
        part.Transparency = fade
        if fade == 1 then
            part.CanCollide = false
        end
    end
end)
0
Do you want it to check if fade is above 1? or that it fades or both? ChrisTheRobloxPlayYT 256 — 4y
0
no i need to check if fade is 1 because thats when the transparency of the block goes invisible omgdodogamer 11 — 4y

1 answer

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

Hello! Here is how to fix it:

local fadeAmount = 0.05
local fadeTime = 0.05
local part = script.Parent
local debounce = false

part.Touched:Connect(function(hit)
    if debounce == false and hit.Parent:FindFirstChild("Humanoid") then
        debounce = true -- Can't touch multiple times
        repeat
            wait(fadeTime)
            script.Parent.Transparency = script.Parent.Transparency + fadeAmount
        until script.Parent.Transparency >= 1 --Checks if it is bigger than or equal to 1
        part.CanCollide = false --Turns off CanCollide
        wait(2)
        repeat
            wait(fadeTime)
            script.Parent.Transparency = script.Parent.Transparency - fadeAmount
        until script.Parent.Transparency <= 0
        debounce = false
        part.CanCollide = true
    end

end)

I tested it, and it works, basically, your problem was that you put a while true do loop. Hope it helps =D

0
thanks! omgdodogamer 11 — 4y
0
No problem! alexfinger21 341 — 4y
0
but how do i make the part respawn after a specific amount of time (sorry i forgot to mention that) omgdodogamer 11 — 4y
0
Okay, I made edits to my script, hope it helps. alexfinger21 341 — 4y
View all comments (3 more)
0
Also, check if your part is anchored alexfinger21 341 — 4y
0
thanks it works now! script helpers like you really are what inspire developers. omgdodogamer 11 — 4y
0
Thanks! alexfinger21 341 — 4y
Ad

Answer this question