When my RemoteFunction gets fired, I want to do something and then return to the RemoteFunction. But, since the action is wrapped in a pcall, it returns to the pcall instead of the RemoteFunction.
My script:
event2.OnServerInvoke = function(player, victim)
if admins[player.Name] then
pcall(function()
if game.Players:FindFirstChild(victim) then
local foundvictim = game.Players:FindFirstChild(victim)
datastore:SetAsync(foundvictim.UserId .. "-BanStatus", true)
foundvictim:Kick([[
You have been banned.
-KiBa]])
return "Success."
else
return "Fail."
end
end)
end
end
event2.OnServerInvoke = function(player, victim)
if admins[player.Name] then
local success, res = pcall(function()
if game.Players:FindFirstChild(victim) then
local foundvictim = game.Players:FindFirstChild(victim)
datastore:SetAsync(foundvictim.UserId .. "-BanStatus", true)
foundvictim:Kick([[
You have been banned.
-KiBa]])
return "Success."
else
return "Fail."
end
end)
return res;
end
end
From my understanding, you create a variable which is nil first. Then in the pcall you change the variable, and then in the ServerInvoke thing you return the variable.
event2.OnServerInvoke = function(player, victim)
local result
if admins[player.Name] then
pcall(function()
if game.Players:FindFirstChild(victim) then
local foundvictim = game.Players:FindFirstChild(victim)
datastore:SetAsync(foundvictim.UserId .. "-BanStatus", true)
foundvictim:Kick([[
You have been banned.
-KiBa]])
result = "Success."
else
result = "Fail."
end
end)
return result
end
end