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

Why does this line yield the thread?

Asked by
drew1017 330 Moderation Voter
8 years ago
CameraReady = false
sR = game:GetService'RunService'

plr = game.Players.LocalPlayer
print'1'
repeat wait() until plr.Character
print'2'
if plr.Character then workspace.Remotes.engine:InvokeServer() end
print'3'

(localscript)

Plain and simple, ''3'' doesn't print. the script triggered by the Engine remotefunction does not have any yields either, so i cant see why its stopping the script.

The script triggered by engine by request:

(Yes i know CurrentCamera only works in localscripts this is just for tests)

function workspace.Remotes.engine.OnServerInvoke(plr)
    plr.Character:Destroy()
    workspace.CurrentCamera.CameraSubject = workspace.Thingy.Head --workspace.Thingy.CameraPos
    wait(.1)
    workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
    wait(.1)
    workspace.CurrentCamera.CoordinateFrame = workspace.CurrentCamera.CoordinateFrame * CFrame.new(3.5, 0, 0)
    wait(1)
    workspace.CurrentCamera.CoordinateFrame = workspace.CurrentCamera.CoordinateFrame
    workspace.Remotes.localengine:InvokeClient(plr)
    plr.CameraMode = Enum.CameraMode.LockFirstPerson
end

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

workspace.Remotes.localengine:InvokeClient(plr) is the problem.

If you don't define what a RemoteFunction should do, Invoking it will wait until you do, so that it return an answer.


That behavior can be tested pretty easily:

-- localscript
local now = tick()
print("got", game.ReplicatedStorage.RemoteFunction:InvokeServer())
print(tick() - now)
-- script
wait(10)
print("going!")
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player)
    print("invoked!")
    return 5
end

Output:

going!

invoked!

got 5

9.8356204032898

Ad

Answer this question