Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make the item say it's already bought?

How can I make the game tell that I already have the item in my backpack so it doesn't repeat its purchase?

local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats:FindFirstChild("Cash").Value >= price.Value then 
		player.leaderstats:FindFirstChild("Cash").Value = player.leaderstats:FindFirstChild("Cash").Value - price.Value
		game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)
	end
end)

1 answer

✓ Accepted answer

Hello, fr2013!

I'm assuming that tool.Name is the item name

local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
    if player.Character:FindFirstChild(tool.Name) or player.Backpack:FindFirstChild(tool.Name) then return end --Returns if player is holding (or have on the backpack) the tool name (tool.Value)
    if player.leaderstats:FindFirstChild("Cash").Value >= price.Value then 
        player.leaderstats:FindFirstChild("Cash").Value = player.leaderstats:FindFirstChild("Cash").Value - price.Value
        game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)
    end
end)

Good Luck with your games

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.