I am using FE for the first time, and I have a shop GUI. In workspace, there is a script called BuyProductHandler. In the GUI button, there's a local script.
This is the BuyProductHandler script:
script.BuyProduct.OnServerInvoke:connect(function(plr, itemname, price)
local stats = plr:FindFirstChild("leaderstats")
local inventory = plr:FindFirstChild("Inventory")
local item = inventory:FindFirstChild(itemname)
local money = stats:FindFirstChild("Z-Coins")
if money.Value >= price then
money.Value = money.Value - price
item.Value = true
return true
else
return false
end
end)
script.PlayerHasItem.OnServerInvoke:connect(function(plr, itemname)
local inventory = plr:FindFirstChild("Inventory")
local item = inventory:FindFirstChild(itemname)
if item.Value == true then
return true
else
return false
end
end)
script.Equip.OnServerInvoke:connect(function(plr, itemname, itemtype)
local inventory = plr:FindFirstChild("Inventory")
local item = inventory:FindFirstChild(itemname)
local itempath = game.Lighting.PurchaseObjects:FindFirstChild(itemtype)
local obj_item = itempath:FindFirstChild(item)
if itemtype == "effect" then
obj_item:Clone().Parent = plr.Character.Torso
elseif itemtype == "weapon" then
obj_item:Clone().Parent = plr.Backpack
elseif itemtype == "hat" then
obj_item:Clone().Parent = plr.Character
end
end)
This is the local script:
price = 40
item = script.Parent.Parent.Name
Handler = workspace.BuyProductHandler
t = "effect"
script.Parent.MouseButton1Click:connect(function()
if Handler.PlayerHasItem:InvokeServer(game.Players.LocalPlayer, item) == true then
Handler.Equip:InvokeServer(game.Players.LocalPlayer, item, t)
else
if Handler.BuyProduct:InvokeServer(game.Players.LocalPlayer, item, price) == true then
Handler.Equip:InvokeServer(game.Players.LocalPlayer, item, t)
end
end
end)
Here is the console:
18:33:30.716 - OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available 18:33:30.719 - Stack Begin 18:33:30.721 - Script 'Workspace.BuyProductHandler', Line 1 18:33:30.723 - Stack End
