local success, result = pcall(function ()
return "foobar"
end)
print(success, result)
The pcall should not be a deterrent to you using remotes since that’s the only way to accomplish what you’re trying here, so it’s more likely that you aren’t using the pcall properly or don’t understand how to use it more than that you can’t use remotes here and that they prevent you from handling this issue.
If this isn’t helpful then you’re going to need to supply more details, such as the code you’re working with, because otherwise the only real answer here is “use remotes” despite what the OP says.
Ok i managed to make it fire to the server but the server cannot recognize it.
ServerScript:
--Services--
local RP = game:GetService("ReplicatedStorage")
--Variables--
local Remotefunc = RP.SendId
local ModuleFolder = RP.Modules
---modules---
local recentidmodule = require(ModuleFolder.CreateRecentId)
local getcharappearancemodule = require(ModuleFolder.GetCharAppearance)
local frame = Instance.new("Frame")
local new = recentidmodule:new(frame)
Remotefunc.OnServerInvoke = (function(plr,PlayerId)
if type(PlayerId) ~= "number" then
return warn("not number")end
new = new + PlayerId
print(PlayerId)
end)
Client:
---Services---
local RP = game:GetService("ReplicatedStorage")
----Variables---
local Textbox = script.Parent.IdFrame
local button = script.Parent.Button
local RecentIds = script.Parent.RecentIdsFrame
local event = RP.SendId
button.MouseButton1Click:Connect(function()
local success,response = pcall(function()
event:InvokeServer(Textbox.Text)
print(Textbox.Text)
end)
end)
Are you sure you’re using the right type of remote here? The client is not expecting something back from the server to use later so you shouldn’t be using a RemoteFunction. The pcall is also pointless in this circumstance, so you can get rid of it. You aren’t working with unpredictable code.
In the server’s case as well, warn doesn’t return anything, so you shouldn’t be trying to return the result of the call (which is just void). If you needed the server to actually inform the client of the error so they can display it though then you would need a RemoteFunction and it should be written differently such that the server returns a string for the client for the client to use.
Beyond that, I’m not sure what you mean when you say “the server cannot recognise it” - can you elaborate? When you check the console are you seeing the warning being printed out? If you are seeing the “not number” warning in your console when trying to use this system, that’s because you’re passing a string as an argument and checking for a number type, so yes it would fail. Use tonumber to attempt to convert a string into a number. It will return nil if it cannot be done successfully, so from here you can just check for the existence of the argument.
-- You should change to a RemoteEvent anyhow.
OnServerInvoke = function(plr, PlayerId)
-- If you added this print line below, you'd get back "string", not
-- "number", which will not pass the guard clause.
print(type(PlayerId))
PlayerId = tonumber(PlayerId)
if not PlayerId then warn("not a number") return end
-- Your other code goes here
end