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

How could I do so that when someone buys something, they cannot buy it multiple times?

Asked by 4 years ago

I have a shop and it works fine but I want to change that when someone buys a tool, they cannot buy that tool again as long as they have that tool.

Here is the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("BuyTool")

local function buyTool(player, tool)
    if player.leaderstats["????"].Value >= tool.Price.Value then

        player.leaderstats["????"].Value = player.leaderstats["????"].Value - tool.Price.Value

        local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()
        giveTool.Parent = player.Backpack

        local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()
        giveTool.Parent = player.StarterGear
    end
end

remoteEvent.OnServerEvent:Connect(buyTool)
0
if (Player.StarterGrear:FindFirstChild(Tool.Name)) then return end Ziffixture 6913 — 4y
0
In what line do I put that? benjinanas 50 — 4y
0
???? benjinanas 50 — 4y
0
Nvm, Its at the beggining of the function, Thanks! benjinanas 50 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Check if the player already has an item in their inventory,

function buy(plr,tool)
if player.StarterGear:FindFirstChild(tool.Name) == false then
    --do your code here!
end


Or something along those lines

0
Where are you calling your function? JesseSong 3916 — 4y
0
JesseSong, this is an answer to the question. Where I am calling the function is entirely up to the person who asked the qustion. pengalu200 65 — 4y
Ad

Answer this question