Remote event help

So I am busy making an oop inventory system and I am making it so that the players can drop items,

On the client this function is called:

function Slot:DropItem(Player)
	print(Player.Name)--Prints my name
	if self.Item then
		if self.UsedSlots - 1 ~= -1 then
			local Item = Items[self.Item]:Clone()--There is a table tat contains the items
			print("Fire")
			print(Item)--Prints the items name
			game.ReplicatedStorage.Drop:FireServer(Player, Item)
			self.UsedSlots = self.UsedSlots - 1
			if self.UsedSlots == 0 then
				self.Item = nil
			end
		end
	end
end

And then on the server this happens:

game.ReplicatedStorage.Drop.OnServerEvent:Connect(function(Player, Item)
	print(Player.Name)--Prints my name
	print(Item.Name)--Prints my name
end)

The client:

for i, slot in pairs(InventoryFrame:GetChildren()) do
	if slot:IsA("Frame") then
		slot.Button.MouseButton2Click:Connect(function()
			print("Dropping item")
			print(slot.name)
			Slots[slot.Name]:DropItem(Player)
			refreshSlots()
		end)
	end
end

I don’t know why this is happening

It is because Remote events by default pass on the Player instance as the first argument themselves for OnServerEvent, so you don’t need to pass it again from the client, otherwise obviously it would have been so easily exploitable.

So the line here:

game.ReplicatedStorage.Drop:FireServer(Player, Item)

should work fine as

game.ReplicatedStorage.Drop:FireServer(Item)

Nothing needs to be changed on the remote event side, it will work fine, as I said above.

To @WaterJamesPlough And @SpacialEthanRB

I dont think remoteevent can send instance…

I have done it before so I am pretty sure you can.

Even so, network usage can increase significantly, which can lead to lag for those using low-speed networks.
Please make item number and use the item number.

If you send a client sided instance, it will be nil to the server and that is obvious. And @SpacialEthanRB yeah, you should pass the Item name / a different type of reference, as a client sided instance will be nil to the server as I said above.

I didn’t really check out the other part of the script, as the OP’s question was why it was printing the same I believe :slight_smile:

And hacking is also possible.
Hackers can put their parts in the workspace.

So I managed to fix it by storing the table of items on the server instead of in that module script, and I just fire a string to the server.

1 Like

This inventory system that I am making is not for a game, it just for me to learn oop better.

Instances can be passed through remotes so long as both sides can see the said instance. An instance created on the client will obviously return nil if indexed on the server, but indexing the workspace (assuming that was the passed argument) will return the workspace.

As long as there aren’t backdoors in the game, hackers will be only creating the parts in their side, meaning no one else can see it. So it will be nil for the server too.

Except if the game in question has poor security implemented, this will not be the case as anything created on the client will not replicate to other clients or the server without explicit usage of remotes.

I recommend that you look into Roblox’s article on the Client-Server Model before spreading potentially inaccurate information.

1 Like