InvokeClient not working?

It does fire to the client when the player joins (see below) but not in these scenarios:

for _, wep in weps do
	local name, curr, cost = wep.name, wep.curr, wep.cost

	local showcaseWep, useWep = showcase:FindFirstChild(name, true), weapons:FindFirstChild(name, true)
	local wepClone = useWep:Clone()

	for _, part in wepClone:GetDescendants() do
		if not (part:IsA(`Part`) or part:IsA(`MeshPart`)) then continue end
		local clone = part:Clone()

		clone.Anchored = true
		clone.Parent = showcaseWep.Glass
		clone.Position = showcaseWep.Glass.Position

	showcaseWep.Top.Cost.Cost.Text = `{name:gsub(`(%l)(%u)`, `%1 %2`)} ({cost} {curr})`

	Instance.new(`ClickDetector`, showcaseWep)

	showcaseWep.ClickDetector.MouseClick:Connect(function(plr)
		local char = plr.Character

		local l = plr.leaderstats
		local stat = l[curr]

		local function showMsg(msg)
			local plrGui = plr.PlayerGui
			local notif = plrGui.Shop
			local err = notif.Error
			err.Visible = true
			err.TextLabel.Text = msg

			err.Close.MouseButton1Click:Once(function()
				err.Visible = false
			end)
		end
		
		if table.find(funcs:InvokeClient(plr, 'getInventory'), name) then -- client is not fired
			rs.Sounds:FireClient(plr, 9066167010) -- (same problem on the server badges script (line 143), check the last section of inventory -> handler)
			return showMsg(`You already have this sword!`)
		end

		if stat.Value >= cost then
			stat.Value -= cost
			if rs.Funcs:InvokeClient(plr, `equip`) then -- obviously this doesn't work too
				useWep:Clone().Parent = plr.Backpack
			end

			rs.Sounds:FireClient(plr, 8522330758)
		else
			showMsg(`You don't have enough {curr:lower()} to purchase this!`)
			rs.Sounds:FireClient(plr, 9066167010)
		end
	end)
end

game.Players.PlayerAdded:Connect(function(plr)
	wait(wait(wait()))
	print(rs.Funcs:InvokeClient(plr, `getInventory`)) -- the client does return in here but not the other parts wtf 

	local dataInventory = inventoryStore:GetAsync(plr.UserId..`|`..game.PlaceId) or {}
	events:FireClient(plr, `inventory`, dataInventory)

	for _, wep in dataInventory do
		if not wep[2] then continue end
		weapons:FindFirstChild(wep[1], true):Clone().Parent = plr.Backpack
	end
end)

It is happening in this script too:

events.OnServerEvent:Connect(function(plr, event)
		if event ~= `badgeRewards` then return end
		respawnTime = plrs.RespawnTime

		local function give(item, id, parent)
			parent = parent or weps.Others
			
			if not ownb(id) or table.find(funcs:InvokeClient(plr, `getInventory`), item) then return end -- doesn't fire to client.
			-- i've tried this for like an hour I gave up please help nothing works (not remote functions not just waiting no nothing)
			_G.clone(item, parent, plr.Backpack) -- same problem on the buy script (line 64), check the last section of inventory -> handler
		end

		if ownb(92138459916479) then
			respawnTime /= 2
			if ownb(2092864127843328) then
				respawnTime /= 2
				if ownb(3017341561704653) then
					respawnTime /= 2
					if ownb(4022409980214611) then
						respawnTime /= 2.01
					end
				end
			end
		end

		if ownb(860025579394488) then
			plr.Character.Humanoid.MaxHealth += 1
		end

		give(`Bomb`, 549562482551418) -- remains unchanged, just change the function itself
		give(`Boombox`, 370478133968418)
		give(`RocketLauncher`, 3590641607389542)
	end)

The client:
(It has nothing to do with this as it does print the event when the player joins but I will still give the code regardless)

funcs.OnClientInvoke = function(event) -- doesn't fire with Weapons -> System (63) and Badges on server (143), please help.
    print(event)
    
    if event == `getInventory` then
        return inventory:GetChildren()
    elseif event == `equip` then
        return equipped < maxEquipment
    end
end

For context I’ve done basically everything I can and it wasted me a very long time. I also searched at the internet but it’s quite irrelevant

2 Likes

If you add print statements directly before and after the :InvokeClient() bits, do the print statements get outputted?

1 Like

Yes they do I’ve tried that, the other systems below those lines also works

1 Like

You should not be using InvokeClient in the first place
Unless you are doing thread management (you don’t) its an insanely unsafe function that lets laggy player/exploiter crash your entire game/

Then how do I get a value from a client without using InvokeClient? (Remote functions doesn’t work it only lets it do something, it can’t return a value)

Use RemoteEvent or manage threads and kill them if no response for a long time

_G is deprecated, use modules instead; which can edit, read and use from client to client (LocalScript) and vice versa.

Also I recommend you use Suphi’s remote function module.

Just a few suggestions…

I wanted to get the inventory (an instance) of the player and the server won’t have the correct inventory as it’s not client sided, I also needed to parent the weapon to the inventory after some conditions by checking the inventory which the weapon won’t work if I do it on a client.
I just need to know why it is not firing to the client in some situations

You are reinventing the wheel.
Where does it makes sense for inventory to be purely made on a client?

Well it’s not. The inventory table is in another script and if I don’t require the client I would have to require the client, then let the client require the script and then get back the table
I just want to understand why the InvokeClient isn’t working and even if you gave me a workaround I would still need to understand why it isn’t working

Still stretching head, please help!