I have made a buy script where you buy an item and it clones to your backpack from ServerStorage, but it does not work.
How the script is supposed to work is, that when the button is clicked, the currency is subtracted and the item is found in a folder in ServerStorage. Then, the item is cloned to the player’s backpack.
Everything in the script works until the part when the item has to be found.
Script:
script.Parent.MouseButton1Click:Connect(function()
local plr = game.Players.LocalPlayer
local Currency = plr.CurrencyFolder.Currency
local ItemPrice = script.Parent.Parent.Price.Value
local ItemName = script.Parent.Parent.ItemName.Value
if Currency.Value >= ItemPrice then
Currency.Value = Currency.Value - ItemPrice
-- next 2 lines do not work
local Item = game.ServerStorage:WaitForChild("StoredItems"):FindFirstChild(ItemName)
Item:Clone().Parent = plr.Backpack
end
end)
How do I fix this?