HOW TO: Check for child added to a players backpack from the server

Hey! Currently, I’m making an inventory system and I need to protect it better from exploits. I have a remote event which fires from the client when a child is added to the LocalPlayer’s backpack. Clearly, this is easily exploitable. A player can simply add anything to their backpack and it will fire to the server. What I want to do is check for a child added just like I did on the client, but instead on the server. I read about doing a player-added event and using the player parameter from it to find the player’s backpack, but that seems unreasonable.

I haven’t left the code because it’s more of a general question than a specific question to my code.

Any ideas?

Thanks,
Ethan

Is there a reason you can’t use the ChildAdded event of the player’s backpack?

If you check with the client, someone could add whatever items they want to their inventory.

I want to use the ChildAdded event, but I want to check from the server. To do this, I need the player. My question is how would I get the player when there is a child added to the backpack because I can’t just use LocalPlayer.

You can get them from the player list, which is accessible from the server.

local trackedPlayers = {}

game.Players.ChildAdded:Connect(function(newplayer)
	trackedPlayers[newplayer] = newplayer.Backpack.ChildAdded:Connect(yourAntiCheatCheckFunc)
end)

game.Players.ChildRemoved:Connect(function(leavingplayer))
	local event = trackedPlayers[leavingplayer]

	if event ~= nil then
		event:Disconnect()
	end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.