Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this line yield the thread?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.