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?