2 swords clones at per purchase, gives errorr

i get 2 swords at one purchase and gives me error

Players.Da_RealHonestmam.Backpack.SwordOfRedEpicness.Script:9: attempt to call a nil value

ServerScriptService.ToolGiver:5: attempt to index nil with ‘Clone’

local Events = ReplicatedStorage:WaitForChild('Events')
local Items = ReplicatedStorage:WaitForChild('Items')
local Purchase = Events:WaitForChild('Purchase')

local PurchaseScreen = script.Parent.Parent.Main:WaitForChild('PurchaseScreen')

local Player = game.Players.LocalPlayer

local Sidebar = script.Parent:WaitForChild('Sidebar')
for _,shop in pairs(Sidebar:GetChildren()) do
   if shop:IsA('TextButton') then
       
       shop.MouseButton1Click:Connect(function()

       PurchaseScreen.ProductName.Text = shop.Name
       PurchaseScreen.Thumbnail.Image = "rbxassetid://"..shop.ImageID.Value

     end)

       PurchaseScreen.Buy.MouseButton1Click:Connect(function()
       
                if Player.leaderstats.Money.Value >= shop.Price.Value then
                local tool = Items:FindFirstChild(shop.Name)
   
                    Purchase:FireServer(tool,shop.Price.Value)
               end
        end)

    end
end

server

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = ReplicatedStorage:WaitForChild('Events')

Events.Purchase.OnServerEvent:Connect(function(Player, Item, Price)
    local gear = Item:Clone()
    gear.Parent = Player.Backpack
    
    Player.leaderstats.Money.Value = Player.leaderstats.Money.Value - Price
end)

Show us the error, we need that in order to help you

1 Like

According to your error, sidebar doesn’t exist, therefore it’s nil

1 Like

Can we see the server script?? You’ve only included the client.

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = ReplicatedStorage:WaitForChild('Events')

Events.Purchase.OnServerEvent:Connect(function(Player, Item, Price)
    local gear = Item:Clone()
    gear.Parent = Player.Backpack
    
    Player.leaderstats.Money.Value = Player.leaderstats.Money.Value - Price
end)

Alright, so I just done a bit of research to confirm my suspicion, turns out I was right… You can’t send instances through remote events as you are doing…

A simple way to fix this is to store a folder of all your tools inside of Replicated storage then just send the name… You can then just go through the folder to find the correct tool.