What is the fastest way to get the players cmaera position from server?

i already tried a remote function but that takes too long (1 second)
i also tried event but thats returning nil

1 Like

You can’t retrieve a player’s camera position from the server, as each player has their own CurrentCamera instance. Try using a RemoteEvent to get the player’s camera position.

i already tried that but it keeps returning nil

Can you show me what are you sending to the server, and how the server script handles it?

local function RequestCamPos(Plr)
	Request:FireClient(Plr)
	Request.OnServerEvent:Connect(function(plr, Data)
		print(Data)
		return Data
	end)
end

data prints right, it prints out the stuff i want. but when i return it it returns nil?

You are returning the current function, that’s why it returns nil instead of the desired data you want. Try this instead:

local function RequestCamPos(Plr)
	Request:FireClient(Plr)
        local DataRes;
	Request.OnServerEvent:Connect(function(plr, Data)
		print(Data)
	    DataRes = Data
	end)
    repeat task.wait() until DataRes ~= nil
    return DataRes
end

that works, thank you man
char limit

You probably don’t want to be making a new RbxScriptSignal connection to the Request RemoteEvent each time the RequestCamPos() function is called, and not cleaning it up. Set up the connection once at startup, and then have RequestCamPos() just do the FireClient whenever you need to get the data from the client.

If you need the camera position for all players all the time, for example how an FPS game does in order to show all players where everyone else is looking, then it makes more sense to just send the camera position from each client every frame or every few frames, using an UnreliableRemoteEvent (order not guaranteed, but less latency than an ordinary RemoteEvent and WAY less than a RemoteFunction).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.