Remote function InvokeServer() sends nil values

Hello developers.I’m trying to make my custom own badge service plugin to make people’s job easier and helpful functions or events to improve people’s experience badges.

However,today i found out that my RemoteFunction is sending the values to server as nil. Like for an example:

CLIENT:

workspace.RemoteFunction:InvokeServer("This is a string")

SERVER:

workspace.RemoteFunction.OnServerInvoke = function(Text)
    print(Text)
end)

OUTPUT:

nil

I have tried to look up on the issue im facing currently,but i’m sure about this is only me experiencing this issue.since there’s no opened forums about this.

Can anyone help me how do i fix this? any help is appreacited

(sorry if you guys don’t understand i’m a turkish developer)

1 Like

You forgot the Player on the OnServerInvoke.

workspace.RemoteFunction.OnServerInvoke = function(Player, Text)

3 Likes

This “workspace” needs to go away. Make a remote function in replicatedstorage, a place it belongs. Once you fix the naming of them, connection it to a part, or button, or something. LocalScript in starterplayer scripts doesn’t initalize a remote function. You MUST call it, connect it to a touched event, or what I do is a GUI button is easiest. Also on the server please use

function(player, text)

As the player is the first paramiter.

that was an example but thank you for noticing me about this.

it still won’t work in my main script. still sends as nil.

let me send you guys the actual script:

CLIENT:

local toolbar = plugin:CreateToolbar("Badge Service")
local button = toolbar:CreateButton("Manage","Badge Service","rbxassetid://113899266505874")

local Players = game:GetService("Players")

local GUI = script.Parent:WaitForChild("BadgeService")
GUI.Parent = game:GetService("CoreGui")
local CreateFrame = GUI["Create Badge"]
local EditFrame = GUI["Edit Badge"]
local ManagerFrame = GUI["Badge List"]
local DeleteConfirmation = GUI["Delete Confirmation"]
local KeyAccess = GUI["Key Access"]

local Remotes = script.Parent:WaitForChild("Remotes")

local NewBadgeData = {}

button.Click:Connect(function()
	local UserId = game:GetService("StudioService"):GetUserId()
	local Player = Players:GetPlayerByUserId(UserId)
	local HasAccess = Remotes.HasAccess:InvokeServer(Player)
	
	CreateFrame.Visible = false
	if HasAccess == true then
		ManagerFrame.Visible = not ManagerFrame.Visible
		KeyAccess.Visible = false
	else
		ManagerFrame.Visible = false
		KeyAccess.Visible = true
	end
end)

SERVER:

Remotes.HasAccess.OnServerInvoke = function(Player)
	print(Player)
	local profileloaded = BS:LoadProfile(Player)
	
	if profileloaded then
		local Profile = BS:GetProfile(Player.UserId)

		if Profile ~= nil then
			local Data = Profile.Data.HasAccess

			if Data and Data == true then
				return true
			else
				return false
			end
		end
	else
		return false
	end
end

if required, heres the instances they are parented:
image

(the scripts i sended you guys are the part of them. they are not the full version.)

The script may not pass the second if and, since there is no other return, it gives nil

Remotes.HasAccess.OnServerInvoke = function(Player)
	print(Player)
	local profileloaded = BS:LoadProfile(Player)

	if profileloaded then
		local Profile = BS:GetProfile(Player.UserId)

		if Profile then
			return Profile.Data.HasAccess
		end
	end
	return false
end

no, i think you understood wrong or i understood wrongly. i meant to after i use InvokeServer() the server receives the event,but i guess client is sending nil values.

the script gives error at the line local profileloaded = BS:LoadProfile(Player). because the Player value comes everytime as nil. i dont know why.

I need you to test something, please verify that profileloaded = nil by printing it. I also suggest declaring a variable and returning that variable instead of just returning false or true (as a boolvalue). Because I am not sure that is how remote functions work. If profileloaded = nil then you have a problem in that function, not the invokeserver function. If profile loaded does return data, you have an issue with sending bool values to the server directly. Then you should just use the method I talked about declaring a local variable changing it to false or ture and then return .

Oh, I thought it was a script for a game, instead of using RemoteFunction you should use modules, since GetPlayerByUserId won’t work if only you are in the game.

You can’t get the player because “technically” in studio there is no player, the ID is used for async things, example for the module:

function module.HasAccess(UserId: number)
	local profileloaded = BS:LoadProfile(UserId) --> adapt the module to work with the UserID
	if profileloaded then
		local Profile = BS:GetProfile(UserId)
		if Profile then
			return Profile.Data.HasAccess
		end
	end
	return false
end

nope,even i print the player value after server receives the event,still prints nil.the function works fine with other scripts.

oh,im also using userid in the module.but still seems doesn’t works.i think i would just use remote event.or does that could also work?

also how do you guys write the specific text to reply it? i couldn’t figure it out.i had to reply two times.

Nope, it won’t work either, as I said, technically in Roblox Studio you don’t have a Player instance, the best option is modules or BindableEvent


Select the text and “Quote”, or something like that, will appear

i finally did it.

also how do i use bindable events for my script? do you have any tips about it? thank you for developers who helped me about this problem.

well i’m started to think this is a bug because some remote functions are working fine with Plr,value but after some specific remote functions they completely stops working. i think i have to create my new plugin and make it optimized.

Doesn’t sounds like a solution my friend lol.

i marked as solution and its solved hah

Oh you fixed it, what was wrong so others can learn?

let me explain you.

i just removed the old plugin and now remaking it.

easy solution :smiley:

(this was the only chance to do it i felt like remote functions no longer functioning)

So you didn’t fix it, also for anyone that reads this remote functions work fine. Have a great day sir.

Im explaining about the plugin like maybe some remote functions stopped functioning in the plugin.

you too,have a great day.

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