Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
fr2013 88
5 years ago

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

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

0
Thanks! fr2013 88 — 5y
Ad

Answer this question