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

How to make a repeat until loop subtract transparency?

Asked by 4 years ago
Edited 4 years ago

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

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

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.

0
your code only works once a player is on the block, and once they get off of it it's back to normal astonplep 32 — 4y
0
I edited it VitGamer123br 32 — 4y
Ad

Answer this question