2016-12-31 143 views
-2

我真的在ROBLOX制作脚本,针对我的UFO,其中每当UFO从高空经过它播放音频。我做了如下脚本需要帮助的ROBLOX脚本(LUA)

while true do 
    if script.Parent.Parent.Velocity.Magnitude>10 then 
    if local h = hit.Parent:FindFirstChild("Humanoid") 
     then script.parent:play() 
     wait(5) 
    else 
     wait() 
    end 
    wait() 
end 

任何更正将是一个真正的帮助!

谢谢!

+0

你想要什么样的建议? – Vyacheslav

+0

我不认为你应该使用'while'循环。我以前从未为Roblox制作过插件,但是'while'循环会阻止。从[this](http://wiki.roblox.com/index.php?title=Tutorial:Plugins)教程看,它看起来像你想看看钩子 – DavisDude

+0

他从来没有提到任何关于插件@DavisDude – warspyking

回答

0

一切不谈,在根部有很多语法错误的以及实施的错误,都在所有的代码块你给我们不会做你希望它是什么。

但是,这里有一个解决的办法是什么基本的想法:

local newThread = coroutine.create(function() 
    while true do 
     for i, v in game.Players:GetPlayers() 
      local playerListener = workspace[v.Name]["Head"] 
      local ufoListener = workspace.Ufo:FindFirstChild('Listener') 
      local magnitude = (playerListener.Position - ufoListener.Position).magnitude 
      if (magnitude > 10) then 
       script.Parent:play() 
      else 
       wait(0.5) 
      end 
     end 
    end 
end) 

coroutine.resume(newThread) 

从本质上讲,这里的破败:我们正在使用的协同程序使这个while循环不会产生这个线程的烙印。有使用可绑定的事件,也许在那里,从LocalPlayer发射时,它调用服务器 - 一个事件,但我离题了一些服务器 - 客户端握手一些更复杂的渠道。这应该完美地满足您的需求,而不会让您感到困惑。