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 3 years ago
Edited 3 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 3 years ago
Edited 3 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 — 3y
0
I edited it VitGamer123br 32 — 3y
Ad

Answer this question