Remote Function:InvokeClient() not returning a value

Server

--==========Locals==========--

local Event = script:WaitForChild("IsVR")

local Plr = script.Parent.Parent

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

Plr.CharacterAdded:Connect(function()

print("Something")

local IsVR = Event:InvokeClient(Plr)

if IsVR == true then

print("Player Is Using VR")

else

print("Player Is Not Using VR")

end

end)

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

Client

--==========Locals==========--
local Plr = game.Players.LocalPlayer
local VRService = game:GetService("VRService")
local Event = script.Parent:WaitForChild("IsVR")
local UIS = game:GetService("UserInputService")
--==========Main==========--
Event.OnClientInvoke = function()
	local isUsingVR = UIS.VREnabled
	if (isUsingVR) then
		print("User is using a VR headset!")
		return true
	else
		print("User is not using a VR headset!")
		return false
	end
	print("Will return") -- Here
end
--====================KeithKeiser971====================--

Output:
image

Try put the remote function in ReplicatedStorage and have the server and client use the same one.
This might be a replication issue (as in the server and the client have 2 different remote functions).

I Moved The Event To Replicated Storage, Updated Both Scripts With game.ReplicatedStorage:WaitForChild(“IsVR”), but it still prints the same as shown above

Have you tried commenting out the code and just return something?:

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

This is to see if there’s something wrong with the remote.

Hm, maybe the server is invoking the client before your player script is started? Try adding a wait(2) before you invoke the function but after the player joins.

Server

--==========Locals==========--
local Event = game.ReplicatedStorage:WaitForChild("VrCheck")
local Plr = script.Parent.Parent
--==========Main==========--
Plr.CharacterAdded:Connect(function()
	wait(2)
	print("Something")
	local IsVR = Event:InvokeClient(Plr)
	if IsVR == true then
		print("Player Is Using VR")
	else
		print("Player Is Not Using VR")
	end
end)
--====================KeithKeiser971====================--

client

--==========Locals==========--
local Plr = game.Players.LocalPlayer
local Event = game.ReplicatedStorage:WaitForChild("VrCheck")
local UIS = game:GetService("UserInputService")
--==========Main==========--
Event.OnClientInvoke = function()
	--[[local isUsingVR = UIS.VREnabled
	if (isUsingVR) then
		print("User is using a VR headset!")
		return true
	else
		print("User is not using a VR headset!")
		return false
	end]]
	print("Invoked")
	return false
end
--====================KeithKeiser971====================--

Now Nothing Outputs?

Try this:

Server script in ServerScriptService

local Event = game.ReplicatedStorage:WaitForChild("IsVR")

game.Players.PlayerAdded:Connect(function(Plr)
    Plr.CharacterAdded:Connect(function()
        print("Something")
        local IsVR = Event:InvokeClient(Plr)
        if IsVR then
            print("Player is using VR")
        else
            print("Player is not using VR")
        end
    end)
end)

Local script in StarterPlayerScripts?

local Plr = game.Players.LocalPlayer
local Event = game.ReplicatedStorage:WaitForChild("IsVR")
local UIS = game:GetService("UserInputService")

Event.OnClientInvoke = function()
    if UIS.VREnabled then
        print("Player is using VR")
        return true
    else
        print("Player is not using VR")
        return false
    end
end

It Turns Out StarterGui Was Reseting The Script Everytime I Spawned, It Had Enough Time To Print ‘Something’, But Not Enough To Get A Response From The Client, When I Added The Wait(2) It Doesn’t Have Enough Time To Print Anything. I Put The Script Tree Into A ScreenGui With Reset On Spawn Off(I Also Added Another .Parent To The Plr Location In The ServerScript) And Now It Outputs This: image Now That IK What Was Wrong I Believe I Can Get It To Work. Thanks For All Your Help

Instead of using script.Parent.Parent to define the player, try using

game:GetService("Players").PlayerAdded:Connec(function(Player)

end)

The 2 players might be different.

That’s not actually true, the way he did it was fine.