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.

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

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

01local part = script.Parent
02 
03local function onPartTouched(otherPart)
04 
05    local partParent = otherPart.Parent
06    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
07    if humanoid then
08                wait(0.1) -- I can adjust this
09                part.Anchored = false
10        --repeat part.Transparency - 20
11        --until part.Transparency = 0
12        end
13    end
14 
15part.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

01local function onPartTouched(Part)
02    for i = 1,0,-0.1 do
03        Part.Transparency = i
04        wait()
05    end
06end
07 
08local part = script.Parent
09 
10local function onPartTouched(otherPart)
11    local partParent = otherPart.Parent
12    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
13    if humanoid then
14                wait(0.1) -- I can adjust this
15                part.Anchored = false
16        OnPartTouched(part) 
17   end
18 end
19 
20part.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