Ive been trying to do a gui shop to buy items. When a button is pressed, a remote event gets triggered and then a script in serverscript service checks if you have enough currency to buy it. But im trying to make that you need materials to buy it. If you can help, i would appreciate it.
BuyToolEvent.OnServerEvent:Connect(function(player,ToolName, ItemPrice, CurrencyType)
local Tool = ServerStorage:FindFirstChild("CraftingTools"):FindFirstChild(ToolName)
local CurrencyToUse = Iron
if Tool then
if player.leaderstats."CurrencyType".Value >= ItemPrice then
-- player.leaderstats.Iron.Value >= 6
player.leaderstats.Iron.Value = player.leaderstats.Iron.Value -6
game.ServerStorage.CraftingTools.IronBat:Clone().Parent = player.Backpack
end
end
end)
BuyToolEvent.OnServerEvent:Connect(function(player, ToolName, ItemPrice, CurrencyType)
local Tool = game.ServerStorage:FindFirstChild("CraftingTools"):FindFirstChild(ToolName)
if Tool then
if player.leaderstats[CurrencyType].Value >= ItemPrice then
player.leaderstats[CurrencyType].Value -= 6
game.ServerStorage.CraftingTools.IronBat:Clone().Parent = player.Backpack
end
end
end)
BuyToolEvent.OnServerEvent:Connect(function(player,ToolName, ItemPrice, CurrencyType)
local Tool = ServerStorage:FindFirstChild(âCraftingToolsâ):FindFirstChild(ToolName)
if Tool then
if player.leaderstats[CurrencyType].Value >= ItemPrice then
player.leaderstats[CurrencyType].Value = player.leaderstats[CurrencyType].Value -ItemPrice
Tool:Clone().Parent = player.Backpack
end
end
end)
Still the error shows up if you try to compare an Instance to a number
@dav2777 In the LocalScript where you have the BuyToolEvent:FireServer, is the CurrencyType a string value there as well or is it a IntValue/NumberValue named âIronâ?
BuyToolEvent.OnServerEvent:Connect(function(player, ToolName, ItemPrice, CurrencyType)
print(ItemPrice, typeof(ItemPrice))
local Tool = game.ServerStorage:FindFirstChild("CraftingTools"):FindFirstChild(ToolName)
if Tool then
if player.leaderstats[CurrencyType].Value >= ItemPrice then
player.leaderstats[CurrencyType].Value -= ItemPrice
game.ServerStorage.CraftingTools.IronBat:Clone().Parent = player.Backpack
end
end
end)