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
9 years ago
1CameraReady = false
2sR = game:GetService'RunService'
3 
4plr = game.Players.LocalPlayer
5print'1'
6repeat wait() until plr.Character
7print'2'
8if plr.Character then workspace.Remotes.engine:InvokeServer() end
9print'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)

01function workspace.Remotes.engine.OnServerInvoke(plr)
02    plr.Character:Destroy()
03    workspace.CurrentCamera.CameraSubject = workspace.Thingy.Head --workspace.Thingy.CameraPos
04    wait(.1)
05    workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
06    wait(.1)
07    workspace.CurrentCamera.CoordinateFrame = workspace.CurrentCamera.CoordinateFrame * CFrame.new(3.5, 0, 0)
08    wait(1)
09    workspace.CurrentCamera.CoordinateFrame = workspace.CurrentCamera.CoordinateFrame
10    workspace.Remotes.localengine:InvokeClient(plr)
11    plr.CameraMode = Enum.CameraMode.LockFirstPerson
12end

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 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:

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

Output:

going!

invoked!

got 5

9.8356204032898

Ad

Answer this question