Hello developers, I need some help on making an inventory system. I use a RemoteFunction called "SlotDataRemoteFunction" to ask the server what tool they need and returns the name back to change the slot text. The LocalScript works, I have tested it but now it comes to the problem. In the server script, I have typed down a touched event, it does invoke, but before touching it, it puts the text inside the first slot(Slot1) anyway.

-- Local Script --
local remoteFunction = game:GetService("ReplicatedStorage"):WaitForChild("SlotDataRemoteFunction")
local slot = script.Parent.Slot1
local slot2 = script.Parent.Slot2
local slot3 = script.Parent.Slot3
function slotItem(itemName)
	if slot.Used.Value == false then
		slot.Text = itemName.Value
		slot.Used.Value = true
	elseif slot.Used.Value == true then
		if slot2.Used.Value == false then
			slot2.Text = itemName.Value
			slot2.Used.Value = true
		elseif slot2.Used.Value == true then
			if slot3.Used.Value == false then
				slot3.Text = itemName.Value
				slot3.Used.Value = true
			else
				print("There is no space in your backpack")
			end
		end
	end
end
remoteFunction.OnClientInvoke = slotItem
-- Server Script --
local remoteFunction = game:GetService("ReplicatedStorage"):WaitForChild("SlotDataRemoteFunction")
local function invoke(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	remoteFunction:InvokeClient(plr,script.Parent.ItemName)
end
script.Parent.Touched:Connect(invoke)

By the way, I have checked if anything is nil and I have also used a pcall function.