I`m making a script for my UFO in ROBLOX where whenever the UFO passes overhead it plays an audio. I made a script that goes as follows
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
Any corrections would be a real help!
Thanks!
Everything aside, at the root there are a lot of syntax errors as well as the error of implementation, all in all the code block you've given us won't do what you wanted it to.
However, here's a basic idea of what the solution is:
Essentially, here's the rundown: We're using coroutines so this while loop doesn't yield this thread for all eternity. There are some more complex avenues using bindable events and maybe some server-client handshake where, when fired from the LocalPlayer, it calls an event in the server- but I digress. This should be perfect for your needs without confusing you too much.