Cloned Item in RemoteFunction is not cloned on the Server

I’m making a shop system for my game, when a button is pressed, the Client invokes the server to reduce the players money, and clone the item into the players backpack. However, the server isn’t really cloning it on the serverside, resulting that the item on on the players client only.

Serverscript

BuyItemRF.OnServerInvoke	=function(Player, ItemName)
	local Price
	local FoundItem
	for _,Folder in pairs(Weapons:GetChildren()) do
		for _,Item in pairs(Folder:GetChildren()) do
			if ItemName == Item.Name then
				FoundItem=Item
				break
			end
		end
	end
	local ModuleFolder=ReplicatedStorage.Assets.WeaponModules
	local Module
	if ModuleFolder:FindFirstChild(ItemName) then
		Module	=require(ModuleFolder[ItemName])
		Price	=Module.Price
	else
		print("Debug: "..FoundItem.Name.." | "..script.Name)
		Price	=Pricelist[ItemName]
	end
	if PlayerData[Player.UserId]["Cash"] > Price then
		IncrementPlayerDataLocally(Player, "Cash", -Price)
		if FoundItem then
			FoundItem:Clone().Parent = Player.Backpack
		end
		ReplicatePlayerDataRE:FireClient(Player, PlayerData[Player.UserId])
		return true
	else
		return false
	end
end

I need the Server to return the true/false, which is why I used a remote function, but I guess I misunderstood on how they work. Is there any second solution to fix this, and keeping the ability to return something back to the client?

remote functions do return values to the client. Try moving this part out of the if statement

...
if condition then
    return true
end
return false

this way you assure that the function will always return a value, and this doesn’t cause any problems since after using return, the function will stop completely.
If it still doesn’t return any value the problem is probably on the client

1 Like

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