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")
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)
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
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:
(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
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.