Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

Do you want it to check if fade is above 1? or that it fades or both?

0

no i need to check if fade is 1 because thats when the transparency of the block goes invisible

1 answer

✓ Accepted answer

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

7 comments

0

thanks!

0

No problem!

0

but how do i make the part respawn after a specific amount of time (sorry i forgot to mention that)

0

Okay, I made edits to my script, hope it helps.

0

Also, check if your part is anchored

0

thanks it works now! script helpers like you really are what inspire developers.

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.