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

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

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)

4 comments

0

if (Player.StarterGrear:FindFirstChild(Tool.Name)) then return end

0

In what line do I put that?

0

????

0

Nvm, Its at the beggining of the function, Thanks!

1 answer

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

2 comments

0

Where are you calling your function?

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.

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