So I’ve made some GUI for a shop system. My shop items are in Server Storage. How would I go and make a script where the button to buy an item check a player inventory for wood, deletes the wood, the replaces it with a sword, for example???
Check is player inventory have wood → If there is wood, delete wood → Clone sword from Server Storage → Parent the cloned item to player backpack.
i have an idea but cant test right now
sorry the comments are broken too
if player.backpack.wood or player.wood do
—if there is wood remove then add sword
player.wood:Destroy()
local swordclone = game.serverstorage.sword:Clone()
swordclone.parent = player
else
—if there is no wood add sword
local swordclone = game.serverstorage.sword:Clone()
swordclone.parent = player
end
player clicked a button
check if the player have enough wood
if the player doesnot have enough wood give him a popup/warn message
if he does then send a remote event to the server with the name of the item that
he wants to buy
Server
recive the remote event
checks if the player have enough wood
Player.Wood -= ItemToBuy.Price
clone the gear from Server Storage
make the cloned gear a parent of player`s backpack
That Is EveryThing👍
and if the wood is a “Tool” then you can destroy it with :Destroy
you can check the number of wood Tools in the backback by looping through it and checking if the tool name == “Wood” or ur tool name and then increment a value by 1
This should give you a basic idea of how to do it. (Written in the forum, not tested, of course there is more to code like the UI and all that but this is basically the core functions for a shop)
local SwordCosts = {
Sword1 = 29,
Sword2 = 49
}
local function CheckWood()
If Player and Player.Backpack:FindFirstChild("Wood") then
local W = Player.Backpack:GetChildren()
local Index = 0
for i = 1, #W do
if W[i].Name == "Wood" then
Index = Index + 1
end
if Index >= #W then
return Index
end
end
end
end
local function IsEnoughWood()
local Wood = CheckWood()
if Wood >= SwordCosts[ChosenSword] then --ChosenSword would be the name of the Sword the player has chosen to buy
local SwordC = game:GetService("ServerStorage"):FindFirstChild(ChosenSword):Clone()
SwordC.Parent = Player.Backpack
else
return
end