Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with this code?. Not sure what the problem is with this script.Help appreciated

Asked by 5 years ago

Hello, I stopped attempting to learn roblox lua about three months ago, how ever I am getting back into it, and have been going over the basics. But, I don't understand what is wrong with the script. I am just trying to practice right now but I am having trouble, help + what I did wrong would be greatly appreciated!! Thanks.

thevariable= 5
thewrongnumber= 7
wait (5) 
if thewrongnumber == 6 then
    hello()
else if
    thevariable == 5
then    hello()
    end


function hello()
    game.Workspace.Test.BrickColor = BrickColor.new("Black")
    wait(5)
    game.Workspace.Test.BrickColor = BrickColor.new("Purple")
    return
end
0
1.) Get rid of the odd spacing, and correctly indent your code (elseif no space and wait() no space. Also, variable declarations look better if there is a space between the variable and the = sign example: local x = true). 2.) Define your variables with local (example: local thevariable). 3.) Define your function before calling it and define it with local as well(example: local function hello()). User#25115 0 — 5y
0
4.) Don't use return if it serves no purpose. You are not returning a value and the function ends by default at that point anyway. 5.) Use variables effectively for efficiency and ease. You say game.Workspace.Test twice. That is bad enough. Imagine if you had to type it more times. So, create a varaible for test. User#25115 0 — 5y
0
Thanks, I will take your advice :D BossScorp82103 22 — 5y

1 answer

Log in to vote
-1
Answered by
starmaq 1290 Moderation Voter
5 years ago

you cant call a function, if it wasnt made yet. so you have to change some stuff


local thevariable= 5 local thewrongnumber= 7 local function hello() game.Workspace.Test.BrickColor = BrickColor.new("Black") wait(5) game.Workspace.Test.BrickColor = BrickColor.new("Purple") end if thewrongnumber == 6 then hello() else if thevariable == 5 then hello() end

sooo there were a lot of other problems and the one that u hav to fix is spacing, your script gotta be clean, im not sure if its something with your ctrl+c and ctrl+v but if youre working like that in a real script, you gotta fix this my dude. AND NEVER, I REPEAT, NEVER DO A WAIT AT THE TOP OF A SCRIPT.

1
Placing a wait at the top of a script can be beneficial in many circumstances. That part of your answer is incorrect. There is nothing wrong with putting a wait at the top of a script. User#25115 0 — 5y
0
ahem, *alvinblox reference* starmaq 1290 — 5y
0
So? Don't discourage a beginner with poor logic. User#25115 0 — 5y
0
Wrong. You can call a function which wasn't declared yet, as long as it is a global funcrion, which is the case in OP's script. Amiaa16 3227 — 5y
0
oh you cant i didnt know starmaq 1290 — 5y
Ad

Answer this question