Remote Function:InvokeClient() not returning a value

I Am Trying To Check If A User Has A VR Device Connected

My :InvokeClient() Won’t Return, The Client Prints But The Server Does Not, I Haven’t Used Remote Functions Before So I Don’t Know How To Fix This.

The Server Script Is In StarterGUI, The Client Script And Remote Function Are Parented To The Server Script

Server Script:

--==========Locals==========--
local Event = script:WaitForChild("IsVR")
local Plr = script.Parent.Parent
--==========Main==========--
Plr.CharacterAdded:Connect(function()
	local IsVR = Event:InvokeClient(Plr)
	if IsVR then
		print("Player Is Using Virtual Reality")
	else
		print("Player Is A Normal Person")
	end
	print("Done")
end)
--====================KeithKeiser971====================--

Local Script:

--==========Locals==========--
local Plr = game.Players.LocalPlayer
local VRService = game:GetService("VRService")
local Event = script.Parent:WaitForChild("IsVR")
--==========Main==========--
Event.OnClientInvoke = function()
	if VRService.VREnabled then
		print("True")
		return true
	else
		print("False")
		return false
	end
end
--====================KeithKeiser971====================--

The Output Prints “False” From The Client But The Server Doesn’t Print Anything.

2 Likes

Hi you need to do like this with RemoteFunction

local function myFunction()
-- do stuff
end
Event.OnClientInvoke = myFunction

Print the isVR after the Event:InvokeClient(Plr) then tell what it did output.

Try this:

--==========Locals==========--
local Plr = game.Players.LocalPlayer
local VRService = game:GetService("VRService")
local Event = script.Parent:WaitForChild("IsVR")
--==========Main==========--
Event.OnClientInvoke = function()
   return VRService.VREnabled
end
--====================KeithKeiser971====================--

‘Attempt To Call A Boolean Value’

I Replaced My Check Thing On The Server With Just ‘Print(IsVR)’ And It Didn’t Print, Only Printed False From The Client

Look how they did it in the example.
https://developer.roblox.com/en-us/api-reference/callback/RemoteFunction/OnClientInvoke

Try doing literally just anything on the serverscript (like print('yes')), perhaps maybe the script isn’t running?

--==========Locals==========--
local Event = script:WaitForChild("IsVR")
local Plr = script.Parent.Parent
--==========Main==========--
Plr.CharacterAdded:Connect(function()
	print("Something")
	local IsVR = Event:InvokeClient(Plr)
	print(IsVR)
end)
--====================KeithKeiser971====================--

image

Try doing

if IsVR == true then
	print("Player Is Using VR")
else
	print("Player Is Not Using VR")
end

Didn’t Work, Still Printed The Same As Before :confused:

Try with this

--==========Locals==========--
local Plr = game.Players.LocalPlayer
local VRService = game:GetService("VRService")
local Event = script.Parent:WaitForChild("IsVR")
--==========Main==========--
local function IsVR()
	if VRService.VREnabled then
		print("True")
		return true
	else
		print("False")
		return false
	end
end
Event.OnClientInvoke = IsVR
--====================KeithKeiser971====================--

When using a remote function, both ways work. So I think it will just give the same result.

Still Prints ‘Something’ -Server
‘False’ -Client

When it prints ‘False’, is it supposed to? Meaning, when testing it are you using VR?

I Am Not Using VR, It Is Supposed To Print That I Am Not Using Vr/False On The Server And Client

Can you print this?:

Event.OnClientInvoke = function()
	if VRService.VREnabled then
		print("True")
		return true
	else
		print("False")
		return false
	end
	print("Will return") -- Here
end
--==========Locals==========--

local Plr = game.Players.LocalPlayer

local VRService = game:GetService("VRService")

local Event = script.Parent:WaitForChild("IsVR")

--==========Main==========--

Event.OnClientInvoke = function()

if VRService.VREnabled then

print("True")

return true

else

print("False")

return false

end

print("Will return") -- Here

end

--====================KeithKeiser971====================--

It Prints Something-Server And False-Client, But Doesn’t Print Will Return, Also In Studio It Is Marked As Unreachable Code

This is a good sign for debugging, something in your code is infinitely yielding.
Edit: This doesn’t mean something is yielding, misread the code.

Weirdly enough, the documentation uses UserInputService and not VRService, try using UserInputService instead:

2 Likes

Uh…
Maybe try replacing VRService with UserInputService?