I’m working with a local script and a script, trying to do client-server-client communication with a RemoteFunction. What I’m basically doing is a card-game system, where the player clicks cards in their UI, the server processes them, summons the card, and then a function called removeCard() removes (deactivates)the card played in the players hand.
Here is the location of the local script, script, and remotefunction:
--Local Script
local function removeCard(card)
print("removing...", card)
card.Active = false
card.Visible = false
end
func_play_card.OnClientInvoke = removeCard
local function playCardRequest(plr, card, slot)
for i = 1, 2 do
if table.find(board[i], slot) then
local newSlot = table.find(board[i], slot)
print("pre-server invoke", plr, card, i, newSlot)
func_play_card:InvokeServer(card, i, newSlot) --data passed: player, team, slot index, card
end
end
end
--Script
local function isValidPlay(plr, card, team, slot)
local cardData
print("isValidPlay checking", card, team, slot)
for i, v in ipairs(hand[team]) do
print(v["HandCard"], card)
if v["HandCard"] == card then
cardData = v
table.remove(hand[team], i)
print("got cardData", cardData)
end
end
if cardData then
print("spawning", cardData["Name"])
spawnUnit(cardData, team, slot)
print("testing invokeclient")
func_play_card:InvokeClient(plr, card)
end
end
func_play_card.OnServerInvoke = isValidPlay
From what I can tell from the output, pretty much everything in my previous code works (I tested with prints, my other functions seem to work as intended, and the problem points to the line when it runs:
func_play_card:InvokeClient(plr, card)
with the error:
Script that implemented this callback has been destroyed while calling async callback Client - uivisuals_n:70
pointing at line:
func_play_card:InvokeServer(card, i, newSlot)
I don’t know really much about remotefunctions or if I should use it, pcall(), which roblox dev wiki says to use with RemoteFunctions when invoking client. Should I even bother using remote functions to solve this problem?