paul216
|
  |
| Joined: 20 Jul 2008 |
| Total Posts: 231 |
|
|
| 03 Oct 2014 12:37 AM |
So I've got a button to where once you click it, it makes the wedge opaque. Click it one more time, and the wedge becomes transparent again. The problem is, I click it once, it goes opaque, then whenever I try to click it again the function just doesn't work. From what I can narrow down, the first loop is still running despite the presence of a break and until.
local group = script.Parent.Parent local window = group.Wedge local cd = script.Parent.ClickDetector local transparency = group.Wedge local beep = group.Part.ToggleBeep local toggle = group.Part.Toggle
function WindowTrans() beep:Play() if toggle.Value == false then print('Window is going opaque') toggle.Value = true local i = 1 repeat local i = i + .05 transparency.Transparency = transparency.Transparency - .05 wait(.05) if transparency.Transparency == 0 then break end until i == 5
elseif toggle.Value == true then print('Window is going transparent') toggle.Value = false local i = 1 repeat local i = i + .05 transparency.Transparency = transparency.Transparency + .05 wait(.05) if transparency.Transparency == .5 then break end until i == 5 else print('The world is in hysteria') end end
cd.MouseClick:connect(WindowTrans) |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2014 12:46 AM |
Why would you want to make i go to 5 when a part becomes completely transparent at 1?
also try using a coroutine, since they don't make the script yield at all.
coroutine.create(coroutine.resume(function() repeat local i = i + .05 transparency.Transparency = transparency.Transparency + .05 wait(.05) if transparency.Transparency == .5 then break end until i == 5 end)
|
|
|
| Report Abuse |
|
|
|
| 03 Oct 2014 12:58 AM |
yeah, try a coroutine, but I'd reccomend wrap. That's just my opinion.
local index; local item = coroutine.wrap(function(_,__,___) local ___ = ___ or transparency.Transparency; for i=1,__,1 do transparency.Transparency = (_==[[trans]]) and i/10 or ___+-i/10; end; end);
cd.MouseClick:connect(function() index = (index==nil) and true or not index; local input = index and [[other]] or [[trans]]; item(input, 10); end); |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2014 12:58 AM |
Sorry the first code I gave had a small bug coroutine.resume(coroutine.create(function() repeat local i = i + .05 transparency.Transparency = transparency.Transparency + .05 wait(.05) if transparency.Transparency == .5 then break end until i == 5 end) |
|
|
| Report Abuse |
|
|