Giving multiple items

I am currently making a trail shop GUI that allows you to select the item you want to see, preview it, and then possibly buy it with a buy button. It looks like this at the moment:


The imagelabels are all the trails and the preview is on the right. The problem is, when you use the buy button to purchase the previewed item, it purchases every single trail in the trailfolder. How can I fix this?
The first script is a local script located in the shop gui.

local shopFrame = game.StarterGui.Shop:WaitForChild("Frame")
local itemScroller = script.Parent
local itemPreview = script.Parent.Parent.ItemPreview
local trailsFolder = game.ReplicatedStorage:WaitForChild("Trails")
local ownedTrailsFolder = game.Players.LocalPlayer:WaitForChild("OwnedTrails")
local shopFrame = script.Parent.Parent


function updateShop ()
	
	
	local ownedTrails = ownedTrailsFolder:GetChildren()
	
	for i, trail in pairs(itemsFolder:GetChildren()) do
		local name = trail.Name 
		local price = trail.Price.Value
		local desc = trail.ItemDescription.Value
		local imagepreview = trail.Folder.ImageLabel

		local itemSelection = script.ItemSelection:Clone()

		itemSelection.Parent = itemScroller

		itemSelection.MouseButton1Click:Connect(function()
			itemPreview.Title.Text = name
			itemPreview.TextButton.Text = "Buy for " .. price
			itemPreview.Desc.Text = desc
			itemPreview.PreviewImage.Image = imagepreview.Image
			itemPreview.Visible = true
		end)
		itemPreview.TextButton.MouseButton1Click:Connect(function()
			game.ReplicatedStorage.TrailSelectedRE:FireServer(true, trail)
		end)


	end
end


updateShop()
updateInventory()

ownedTrailsFolder.ChildAdded:Connect(function()
	updateShop(); updateInventory()
end)

The next script is a normal script in serverscriptservice:


local trails = game.ReplicatedStorage:WaitForChild("Trails")


game.ReplicatedStorage.TrailSelectedRE.OnServerEvent:Connect(function(plr, buying, item)
	
	print("Message Recieved")

	if buying and not plr.OwnedTrails:FindFirstChild(item.Name) then

		local price = item.Price.Value
		local coins = plr.leaderstats.Coins

		if price <= coins.Value then

			coins.Value -= price


			item:Clone().Parent = plr.OwnedTrails
		end
	

	elseif not buying and plr.OwnedTrails:FindFirstChild(item.Name) then

		local char = plr.Character

		if not char or not char:FindFirstChild("HumanoidRootPart") then return end

		for i, child in pairs(char.HumanoidRootPart:GetChildren()) do


			if child:IsA("Trail") then child:Destroy() end
		end


		local newTrail = item:Clone()

		newTrail.Attachment0 = char.HumanoidRootPart.TrailTop
		newTrail.Attachment1 = char.HumanoidRootPart.TrailBottom

		newTrail.Parent = char.HumanoidRootPart
	end
end)

Note: If you find any issues with my script that might cause problems in the future, please communicate them with me. Another note is that I did not include some parts of the script for length reasons. If you want to see them, just tell me. If you have any questions, just ask.

It it is because you loop through all the tools and have no kinda of filter. You should filter out the one u want via an if statement (you could just do it via the name or smthing and pass through the name to the function via the name of the tool so when ur looping through them all it only runs the thing you want not every tool in the folder

I filter out the one the user wants by itemSelection. I know it is filtering out that singular one because it is getting the name, description, and image of the item. How would I change the function of the buybutton so it is sending information to the server that the itemSelection trail is the one needed to be bought?

Could you not just send the name of the trail and then like either use an if statement but I feel that would be inefficient so you could just like do it by getting the trail I think.

Do you send information to the server script using the inside of the parenthesis of

game.ReplicatedStorage.TrailSelectedRE:FireServer(true, trail)

You are iterating through a loop to give an object, try adding some debounce and add a function that checks if the player already has the trail. If this worked, please leave a like and mark this post as solved

I added an if statement to the server script making sure that the item is not in the inventory. But, I found out the issue is coming from the local script because whenever I click the button, it is sending 6 messages which means it is trying to buy all of the trails. What do I change in the local script so it is only sending a message for the item previewed?