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

How to make a repeat until loop subtract transparency?

this code will go into a block that falls when a player steps on it, I also want the transparency to go down after it unanchores.

repeat part.Transparency - 20
		until part.Transparency = 0

and this code makes it fall, but when I add the other code it doesn't work.

local part = script.Parent
 
local function onPartTouched(otherPart)

    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
		        wait(0.1) -- I can adjust this
		        part.Anchored = false
		--repeat part.Transparency - 20
		--until part.Transparency = 0
		end
    end
 
part.Touched:Connect(onPartTouched)

1 answer

Use for i loops, they are mean't to do things like that

local function onPartTouched(Part)
	for i = 1,0,-0.1 do
		Part.Transparency = i
		wait()
	end
end

local part = script.Parent

local function onPartTouched(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
                wait(0.1) -- I can adjust this
                part.Anchored = false
		OnPartTouched(part)  
   end
 end
 
part.Touched:Connect(onPartTouched)

I hope this helps.

2 comments

0

your code only works once a player is on the block, and once they get off of it it's back to normal

0

I edited it

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