Boolean doesn't get returned from function

The boolean value that is supposed to be return from the function ran from the ModuleScript doesn’t return correctly and just returns a blank value when I print it, but when I print it directly from the module, it returns it normally:
image
Any reasons why?

Here’s the module

local test = {}

function test:httpEnabled() : boolean
	script.Server:FireServer()
	script.Client.OnClientEvent:Connect(function(arg)
		return arg
	end)
end

return test

Here’s the server script:

script.Parent.Server.OnServerEvent:Connect(function(plr : Player)
	local test = pcall(function()
		game:GetService"HttpService":GetAsync"http://www.google.com"
	end)
	script.Parent.Client:FireClient(plr, test)
end)

And here’s the local script:

test = require(workspace.test)
print(test:httpEnabled())

You can solve this by implementing the following code:

Basically:

function test:httpEnabled(): boolean
	local timeout = 5 --wait for a maximum of 5 seconds, else nil
	script.Server:FireServer()
	local arg = waitEvent(script.Client.OnClientEvent, timeout)
	return (not not arg) --so it returns a boolean(if nil it returns false)
end

PS: You could also use the default Wait() but the cost is that it yields the script for an infinite amount of time until the server responds, so to use it you must be 100% sure the server will respond:

function test:httpEnabled(): boolean
	script.Server:FireServer()
	local arg = script.Client.OnClientEvent:Wait()
	return (not not arg)
end

Thank you so much! I really appreciate your help.

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