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

How do I make this script to only buy a tool once and not multiple times?

player = script.Parent.Parent.Parent.Parent.Parent
money = player.leaderstats.Cash 
price = 5 
tool = game.Lighting:findFirstChild("Tool")


function buy()
	if money.Value >= price then
		money.Value = money.Value - price
		local a = tool:clone()
		a.Parent = player.Backpack
		local b = tool:clone()
		b.Parent = player.StarterGear

	end
end
script.Parent.MouseButton1Down:connect(buy)

1 answer

What you need to do before running this script:

  1. Make a bool value inside the script called AlreadyPurchased
  2. Use the script below

Script:

player = -- Path to player here --
money = player.leaderstats.Cash 
price = 5 
tool = -- Path to tool --
local Value = script.AlreadyPurchased


function buy()
   if script.AlreadyPurchased == true then
   return
   else
    if money.Value >= price then
        money.Value = money.Value - price
        local a = tool:clone()
        a.Parent = player.Backpack
        local b = tool:clone()
        b.Parent = player.StarterGear

    end
end
script.Parent.MouseButton1Down:connect(buy)

Also if you like you can add a datastore so it saves. Hope this helps!

2 comments

0

I inserted in the paths from the other script and also added the bool value inside the script but it doesn't seem to work for me :(

0

Oh! I am sorry about that, I will try to get a new script that might work.

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