2016-12-31 22 views
1

我试图在我的ROBLOX地方制造一个UFO,并且想要创建一个当UFO通过头顶时会播放音频的系统。我创建了一个零件,在零件中插入了一个音频,然后在零件内放置了一个脚本。所以它看起来像:如何在Lua中使用多个If?

本部>音频 - >脚本

我计划的系统时,一个人形触摸注册,而如果部分会比快说,每秒300个道钉,我想它播放音频(最好的音频将仅适用于由部分触及人饰演)所以我写了一个脚本,去如下:

while true do 
if script.parent.parent.Velocity.Magnitude>299 then 
    script.Parent:play() 
    wait(5) 
    script.Parent:stop() 
else 
    wait() 
end 
wait() 

,你可以看到我错过了关于被触及的人形部分,但我不知道如何记住那个。我对脚本非常陌生,但我不知道这些命令(?)的正确上下文。帮助将不胜感激。

谢谢!

回答

1

您可以使用Lua的逻辑运算符:'和','或'和'不是'是最常用的。对你来说,这听起来像你想要做的事,如:

if (condition1) and (condition2) then 
    play_sound() 
else 
    wait() 
end 

您也可以在“鸟巢”的if语句:

if condition1 then 
    if condition2 then 
     do_something() 
    end 
end 
+0

所以我的脚本到目前为止是: – Marcus

0

除了@的会回答你也可以使用elseif检查不同的条件。

if (conditionA) then 
elseif (conditionB) then 
end 

如果conditionA为true,则不会检查下一个语句,因此顺序非常重要。

while true do 
if script.parent.parent.Velocity.Magnitude>299 then 
if(humanoidIsTouchedd()) then 
    script.Parent:play() 
    wait(5) 
    script.Parent:stop() 
elseif (somethingElseIsTouched()) 
    doSomethingElse() 
else 
    wait() 
end 
wait()