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

How do I insert a 'do nothing' line?

Asked by 5 years ago
Edited 5 years ago

Hi,

I'm trying to insert an if statement to play a sound with an elseif statement to not play the sound if ... happens. How do I insert a line to do nothing? I've tried:

if ... then
script.Parent.Music:Play()
else if ... then
end

and

if ... then
script.Parent.Music:Play()
else if ... then
script.Parent.Music:Stop()
end
end

however none of these worked. I'd greatly appreciate if someone could tell me how to do this. Thanks :)

0
else return end WillBe_Stoped 71 — 5y
0
^^ NickAtNick 163 — 5y
0
You are clearly confused with the difference between else if and elseif. You are basically telling the script "if no other condition has been met, then do this condition", which literally makes no sense. DeceptiveCaster 3761 — 5y
0
Thanks for your replies. I may not have worded my question correctly, but I realized that I had to do 'if ... and ... then' as there were 2 conditions. 1tinytaco 15 — 5y

3 answers

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

That's uh, how if statements work. If the condition is true, the sound will play. So if it isn't true, nothing will happen. The sound won't play nor will it get launched into outer space and get sucked in by a black hole.

if ... then
    script.Parent.Music:Play()
end

No need for a 'do nothing' line.

0
Notice his two "if this other condition happens" lines. DeceptiveCaster 3761 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Hi, well, I see you're new to programming and don't yet fully understand the main syntaxes, let me explain the if conditions to you in a way that you don't need a hackerman.

If statements or just if points check if something exists, or if something has a specific value, it all depends on what you ask it to do.

What you might not understand in this context is how it is executed, if the condition or checks are not met, the if statement will not execute the code inside, and just carry on if there's more, for example:

local Cars = 6
local SkyColor = "blue"

if Cars == 7 then
print("There are 7 cars")
end
if SkyColor == "blue" then
print("The sky is blue")
end

Expected output:
> The sky is blue
Log in to vote
0
Answered by
len_ny 8
5 years ago

im pretty sure you are going for something anti-exploitive, heres a good way to do such a thing

if not (...) then
    -- do stuff
end

Answer this question