generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Loops not ending

Previous Thread :: Next Thread 
paul216 is not online. 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
SethDusek5 is not online. SethDusek5
Joined: 26 Mar 2011
Total Posts: 2580
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
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
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
SethDusek5 is not online. SethDusek5
Joined: 26 Mar 2011
Total Posts: 2580
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image