i have a barrier, and I want to decrease the transparency by 0.1 until it is 0 so that its visible, by using a for loop. I also want it to wait 5 seconds before every 0.1 reduction. However it keeps going to the statement barrier 1 is completed, but its not even visible.
Barrier1 = game.Workspace.Barrier1 Barrier1.Transparency = 1 Barrier1.CanCollide = false Barrier1.Anchored = true cost = 50 script.Parent.MouseButton1Click:connect(function() if game.Players.LocalPlayer.leaderstats.Cash.Value >= cost then game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - cost Barrier1.Anchored = true local BarrierTransparency = game.Workspace.Barrier1.Transparency for BarrierTransparency=1, 0, -0.1 do if BarrierTransparency == 0 then Barrier1.CanCollide = true Barrier1.Transparency = 0 end end print("Your barrier has been completed") else print("Not enough cash") end end)
Instead of using for, use repeat and until statements instead
Replace:
for BarrierTransparency=1, 0, -0.1 do if BarrierTransparency == 0 then Barrier1.CanCollide = true Barrier1.Transparency = 0 end end
With:
repeat Barrier1.Transparency = Barrier1.Transparency - 0.1 -- Will decrease transparency by "0.1" wait(XX) --Replace with a time until Barrier1.Transparency == 0 Barrier1.CanCollide = true Barrier1.Transparency = 0
Try it out and let me know what happens
for loops already yield, so you don't need to check if the for loop has ended inside of it. also, that is not how for loops work. for loops generally iterate a certain amount of times, along with the iteration variable.
local Barrier1 = game.Workspace.Barrier1 for i =1, 0, -0.1 do Barrier1.Transparency = i wait() end Barrier1.CanCollide = true print("Your barrier has been completed")