Only 1 Buy Per Player

hello everyone I need help how can I make the game detect if you have already bought something and not let you buy another

----This is the script without the function that I tried to do

local tool = game.ServerStorage.Shop.Tool["Petal Wand"]
local giver = script.Parent
local canGive = false
local price = 50
local function GiveTool(player)
if player.leaderstats.Money.Value < price then return end
canGive = true
player.leaderstats.Money.Value = player.leaderstats.Money.Value - price
local clone = tool:Clone()
clone.Parent = player.Backpack
wait(0.1)
canGive = false
end
giver.ClickDetector.MouseClick:Connect(function(player)
GiveTool(player)
end)

this is the script that with my detection attempt

local tool = game.ServerStorage.Shop.Tool["Petal Wand"]
local giver = script.Parent
local canGive = false
local price = 50
local function GiveTool(player)
	if player.leaderstats.Money.Value < price then
		if not player.Backpack:FindFirstChild(tool.Name) and not player.Character:FindFirstChild(tool.Name) then return end ------- Need Help Here
		canGive = true
	else
		canGive = false
	end --------
	player.leaderstats.Money.Value = player.leaderstats.Money.Value - price
		local clone = tool:Clone()
		clone.Parent = player.Backpack
		wait(0.1)
		canGive = false
	end
giver.ClickDetector.MouseClick:Connect(function(player)
	GiveTool(player)
end)

yes you can buy and equip the object but you can also buy more than 1 and I don’t know how to do that
to make you can only buy 1

is it in non-local script will that be the problem?

Edited Script

local tool = game.ServerStorage.Shop.Tool["Petal Wand"]
local giver = script.Parent
local canGive = false
local price = 50
local function GiveTool(player)
	if player.leaderstats.Money.Value < price then
		if not player.Backpack:FindFirstChild(tool.Name) and not player.Character:FindFirstChild(tool.Name) then return end ------- Need Help Here
		canGive = true
	else
		canGive = false
	end --------
	
	if canGive == true then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value - price
		local clone = tool:Clone()
		clone.Parent = player.Backpack
		wait(0.1)
		canGive = false
	end
end

giver.ClickDetector.MouseClick:Connect(function(player)
	GiveTool(player)
end)
1 Like

It doesn’t let you buy, I modified it and it still lets you buy more than 1

local tool = game.ServerStorage.Shop.Tool["Petal Wand"]
local giver = script.Parent
local canGive = false
local price = 50
local function GiveTool(player) 
	if player.leaderstats.Money.Value < price then return end
		if not player.Backpack:FindFirstChild("Petal Wand") and not player.Character:FindFirstChild("Petal Wand") then ------- Need Help Here
		canGive = true
	else
		canGive = false
	end --------

	if canGive == true then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value - price
		local clone = tool:Clone()
		clone.Parent = player.Backpack
		wait(0.1)
		canGive = false
	end
end

giver.ClickDetector.MouseClick:Connect(function(player)
	GiveTool(player)
end)

well it works just the same it was to change the position and now thanks

local storage = game:GetService("ServerStorage")
local shop = storage.Shop
local tools = shop.Tool
local petalWand = tools["Petal Wand"]

local giver = script.Parent
local debounce = false
local price = 50

local function GiveTool(player)
	if not debounce then
		return
	end
	
	local money = player.leaderstats.Money
	if money.Value < price then
		return
	end
	
	local character = player.Character
	local backpack = player.Backpack
	
	if backpack:FindFirstChild("Petal Wand") or character:FindFirstChild("Petal Wand") then
		return
	end

	money.Value -= price
	local toolClone = petalWand:Clone()
	toolClone.Parent = backpack
	task.wait(0.1)
	debounce = false
end

giver.ClickDetector.MouseClick:Connect(function(player)
	GiveTool(player)
end)