Why is this nil?

Hey, so I’m trying to make the client ask the server if the user is REDACTED, however I’m passing the player as an argument in a RemoteFunction, sadly, in the script, the argument is nil. Why?

Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local Remote = Remotes.lbi
local ServerScriptService = game:GetService("ServerScriptService")
local Modules = ServerScriptService.Modules
local Utils = require(Modules:WaitForChild("Utils"))
local redactmodule = require(Modules:WaitForChild("RedactModule"))

local function giveRedact(plr, arg)
    print(arg)
    local Data = Utils.GetData(arg)
    if not Data then return plr:Kick(Utils.Error("No data.")) end
    local isredvalue = Data.isRedacted.Value
    if isredvalue == true then
        return true
    else
        return false
    end
end

Remote.OnServerInvoke = giveRedact```
LocalScript:
for i,v in pairs(Players:GetChildren()) do
        local redactinfo = game:GetService("ReplicatedStorage").Remotes.lbi:InvokeServer(v)

You’re not passing in “arg”, only the player.

What do you mean? How do I fix it?

You’re not passing arg, but the server is expecting it, so just do:
.Remotes.lbi:InvokeServer(v, YourArgForTheServerHere)

v is the arg though. So I am. Isn’t plr he caller of the function?

Arg
is
nil
because
you’re
not
passing
in
arg.

You can just remove the arg argument, and replace arg with plr.

The arg is v, I’m guessing. Player auto sends as the first argument from the client.

OH. Right, it’s a remote function.

1 Like

So do you have any idea how to fix it?

can i see the Utils Module?

30

Here,

local ServerScriptService = game:GetService("ServerScriptService")
local PlayerData = ServerScriptService:WaitForChild("PlayerData")

local Utils = {}

Utils.Error = function(...)
	local Args = {...}
	local ErrorMessage = table.concat(Args)
	return "Error: " .. ErrorMessage .. "!"
end


Utils.GetData = function(Player)
	if not PlayerData:FindFirstChild(Player.UserId) then return nil end
		
	return PlayerData:FindFirstChild(Player.UserId)
end

return Utils

i tested on my place it’s work fine

Even if arg wasn’t nil, it looks like for the given client, it will attempt to check Data for every player in the game. And if any player has no data, then the calling client will get kicked. This may or may not be the player that actually has no data. I’m guessing that’s not the desired behavior. I could also be reading the code wrong. It just seems like you should be invoking the remote function only for the current client’s LocalPlayer instead of using that for-loop.