Remote Function is not returning anything, yields local script

SCI - Alpha II currently has a major problem loading into the game. The version that is included in this forum post is the Development Private Place, but the issue appears on every place in the experience.

  1. What do you want to achieve?
    When reaching the “Fetching Data…” phase, the local script responsible for loading the assets invokes a remote function to a server script. Said server script sends an event to a separate BindableEvent (accountable for updating the player’s clearance) and then runs a function from a server-based module. Said function returns true once it finishes.

  2. What is the issue?
    The problem mostly appears when multiple players join the game (2-3~). Once the signal reaches the RemoteFunction, it looks like it stops. Sometimes, it appears when playing alone too.

It starts here on the local script.

			local MAX_RETRIES = 100
			local RunService = game:GetService('RunService')
			local coreCall do
				function coreCall(method, ...)
					local result = {}
					for retries = 1, MAX_RETRIES do
						print("try")
						result = [REDACTED].InitPlayer:InvokeServer() -- This is the remote function that's sending the init request to the server.
						if result then
							print("done!")
							return true
						end
						task.wait(1)
					end
					return unpack(result)
				end
			end

			
			repeat wait() until coreCall()

Then, the server receives this on the function:

	[REDACTED].InitPlayer.OnServerInvoke = function(a) if a == plr then [REDACTED].UpdateClearence:Fire([REDACTED]) return securityPermissions:Init(a) end end

The “SecurityPermissions” module and the “UpdateClearence” server receiver both work fine, apparently.

  1. What solutions have you tried so far?
    I’ve been trying to debug this problem for months, but I can’t find the issue with it.
    I searched the DevForum, and couldn’t find anything related to my problem.

I will provide snippets if only necessary. Code parts marked as [REDACTED] are parts I am legally not allowed to show.

Please help me.

From looking at when your code returns and what not, there is an if statement, and only when that if statements conditions are met does it return, put and else in there I think.

That “If” statement checks if the event is from the right player so that they won’t have their data intertwined with another.

1 Like

ok, but still, if the if returns false, it doesn’t return, thus stopping the rest of your code from running, cause it doesn’t return, even if you just make it return nil.

As for why it doesn’t seem to be returning at all, try and put an if statement in there to see if its even being triggered.

I cleaned this up a little. I’m not sure if it’ll change much though

local RunService = game:GetService('RunService')

local function coreCall(method, ...)
	local result;
	
	repeat 
		result = [REDACTED].InitPlayer:InvokeServer()
		print(result)
		task.wait(1)
	until result
	
	return unpack(result)
end

coreCall()

Lemme try that rq, might help somehow.

If the “If” statement is false, that means that it received another player’s call. That’s the point of having this thing. I’m not worried that that’s the case.

1 Like

What they’re talking about is no fallback value returned. Add a return nil outside your if statement.

Also, Remote functions cannot fire incorrectly. If playerA fires a remote event, the server will see that playerA is the player that fired the event.

What’s the plr variable and its purpose?

1 Like

I’ve ran your interpretation, and testing with two players. I got this:
image

Are you passing a table from the server to the client?

Nope.

InitPlayer:InvokeServer()

This sends a signal to the remote function. Since this is a remote function, I don’t have to pass anything since the server already gets the player object.

No, I meant from SERVER → client. This means what are you returning back from the server to the client

I’ve made a change to the server

if a == plr then warn("got init start") ["REDACTED"].UpdateClearence:Fire(plr, false, false) warn("finished fire") securityPermissions:Init(a) return true else return false end end

I added the return part you wanted me to put in the else statement.

The plr’s variable is stored in a function. Said events are in the function itself.

local function onPlayerAdded(plr: Player)	
	local handler = playerHandler.new(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
        --Events here including the fetching data thing.
end

I’m returning true once this whole function is finished:

function perms:Init(plr)
	warn("got init module")
	
	if runService:IsServer() then
		if plr.AccountAge < perms.minAccountAge then
			plr:kick("Your account isn't old enough, You will be able to join in "..  (perms.minAccountAge - plr.AccountAge) .." days.")
		end
		
		if plr:IsInGroup(perms.mainGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinFoundation.Value = true
		end

		if plr:IsInGroup(perms.officefoundersGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinOfficeFounders.Value = true
		end

		if plr:IsInGroup(perms.thefounderguardGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinTFG.Value = true
		end

		if plr:IsInGroup(perms.researchGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinResearch.Value = true
		end

		if plr:IsInGroup(perms.investorGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinInvestor.Value = true
		end

		if plr:IsInGroup(perms.ethicsGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinEthics.Value = true
		end

		if plr:IsInGroup(perms.anomalyactorGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinAnomalyActor.Value = true
		end

		if plr:IsInGroup(perms.medicalGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinMedical.Value = true
		end

		if plr:IsInGroup(perms.eandtGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinEandT.Value = true
		end

		if plr:IsInGroup(perms.isaGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinISA.Value = true
		end

		if plr:IsInGroup(perms.mobiletaskGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinMobileTaskForce.Value = true
		end

		if plr:IsInGroup(perms.deaGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinDEA.Value = true
		end

		if plr:IsInGroup(perms.administrativeGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinAdministrative.Value = true
		end
		
		if plr:IsInGroup(perms.overwatchGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinOverwatch.Value = true
		end
		
		if plr:IsInGroup(perms.nexusGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinNex.Value = true
		end
		
		if plr:IsInGroup(perms.fibGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinFIB.Value = true
		end

		if plr:IsInGroup(perms.manufacturingGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinManufacturing.Value = true
		end

		if plr:IsInGroup(perms.newsGroupID) then
			plr:WaitForChild("TeamFolder").PlayerinNews.Value = true
		end
		return true
	end
end

image

Ight, I tested it again. It gives me false on the second player. But true on the first one.

Your if statement is failing. Why don’t you move the event out of player added?

image

Okay, after a quick test, I deem that the problem is with the server script that I’m replying to. The script can init a player two times, prompting for another player to send an event to the script even if it’s server-side does not exist.

That’s because your event is nested

nested? What does that mean, I never heard of that…

It means within another block of code. For every new player that joins, a new connection is made. This means that if two players join and one of them fires, the code will run twice because you made a connection.

Is this remote only fired to once?