Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't my loop work?

I tried to change a material to change every 5 seconds but this won't work

while true do game.Workspace.Baseplate.Material = Enum.Material.Neon wait(3) game.Workspace.Baseplate.Material = Enum.Material.Plastic end

1 answer

Your script. What's gotta be changed for this to work,* is in bold or has four asterisk stars around the word.

while true do 
game.**W**orkspace.Baseplate.Material =** Enum.Material.Neon** 
wait(3) 
game.**W**orkspace.Baseplate.Material = **Enum.Material.Plastic**
 --add a wait() here so the scirpt does not predict infinity.
end
  1. Make sure, this is in a script and not a local script.
  2. Uncapitalize the W in Workspace
  3. The script wont work because the script thinks
game.**W**orkspace.Baseplate.Material =** Enum.Material.Neon** 
--and
game.**W**orkspace.Baseplate.Material = **Enum.Material.Plastic 
end**

--are variables and not statements.
--Just change Enum.Material.WhatevertheMaterialis to "Neon" or even "Plastic" if you want. (With quotations of course)

Also, I wish someone told me this when I first join Scripting Helpers, you see those two small blue dots with the word "Lua" written over the big dot? That's the icon for a code block.

Though next time, try to highlight your code and the press that button, the "Code Block" button., (you know the, icon with the blue dot I was talking about before)?

It apparently makes your code more readable to a bunch of people on this website.

18 comments

0

Thanks I found out now it's something with my studio that it only works on certain places.

0

The first letter in 'Workspace' is capitalized; it's just that it goes either way, whether you use game.workspace or game.Workspace; also, you MUST capitalize Workspace when using the GetService function, as it wont work otherwise.

0

To note, Enum's aren't a problem at all; however, it's (may be) better to use strings for that kind of purpose, but to each his own. You pointed that there there're variables in his code: there aren't any. And, to finally note, his code wasn't thinking that:

0

Hey, I'm only going from what it says in here. http://wiki.roblox.com/index.php?title=API:Class/BasePart/Material

0

it was thinking "Ok, change the material to this, wait 3 second, then change it to another & back to the original at the same time/ just as quick." The code you provide also has a problem: there's an extra end for the second code. What's to end? There's no function, loop, or if in the second example? Tbh, all I saw in this is misinformation: there's nothing initially wrong in his code; he just nee

0

@JoeRaptor Using Enum's is totally fine; whether the individual uses Enums or strings is totally up to them: saying one is better than the other is subjective.

0

*He just needed another wait after the second material change, and not to change or rewrite his entire code as you have illustrated, but that's just what I think, at least.

0

That was not a second example. That code block was put there for better legibility of what I was referring to.

0

http://wiki.roblox.com/index.php?title=Enumeration#Usage There was no id for there to include enumeration. So what are you insinuating? I reccomend reading the Wiki? @TheeDeathCaster

0

@JoeRaptor There's nothing wrong w/ his code though; it just needed another wait after the second material change, but that's just what I think. I now took another look, and my point still stands about how his original code executed; I wont repeat what I had said about it though.

0

@JoeRaptor When did I mention or talk about an "ID?" Could you, please, point me to where I said that, as I don't recall. I never said that one was better than the other; there's literally no difference, except that one takes a lot more typing, but whoever uses either one is up to them.

0

Strings..? There isn't any strings in his code. But if you're referring to when I said "I never said that one was better than the other; there's literally no difference" & about my saying of Enums & Strings; using Strings & Enums for the same purpose/ functionality doesn't make a difference, as they perform the same exact way; neither one is better than the other, and there's little to no differen

0

*difference between the two (in terms in functionality, that is).

0

I'm done responding; there's nothing more to say, and I've said my peace; good day, sir. ;)

0

Can someone explain me what Enum is? ;D

0

@VladimVladim Enum is short for enumeration. So, that means a set number can refer to something. http://wiki.roblox.com/index.php?title=Enumeration I cant truly wrap my head around Roblox's lua yet because I learned lua in lua 4.3 and not ROBLOX Lua.

0

@TheeDeathCaster *piece.

0

Thanks though ;P gonna try to understand it ;d

This discussion is preserved as it was. New answers, comments, and votes are closed.