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 Script That Purchase An Item One Time Only Without Spamming?

What I want to do is to make the script that make player purchase item one time only instead of spamming. How can I do that? Can anyone help me?

local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local price = 1 
local tool = game.Lighting:findFirstChild("Teleport") 

function picture() 
script.Parent.Parent.Picture.Image = "http://www.roblox.com/asset/?id=51067285" 
script.Parent.Parent.Price.Text = "$1" 
end 

function buy()
wait(0.1)
local money = player.leaderstats.KOs
if money.Value >= price then 
local a = tool:clone() 
a.Parent = player.Backpack
else 
end 
end 




script.Parent.MouseButton1Down:connect(buy) 
script.Parent.MouseEnter:connect(picture)

1 answer

✓ Accepted answer

First Of All, If This Is A Local Script, change the Player Variable. If It's not a local script, which it should be, then Ignore what I have to say. Second Of All, Try using debounce, BUT instead of changing it to its original value, keep it the same.

local player = game.Players.LocalPlayer
local price = 1 
local debounce = false
local tool = game.Lighting:findFirstChild("Teleport") 

function picture() 
script.Parent.Parent.Picture.Image = "http://www.roblox.com/asset/?id=51067285" 
script.Parent.Parent.Price.Text = "$1" 
end 

function buy()
if debounce == false then
debounce = true
wait(0.1)
local money = player.leaderstats.KOs
if money.Value >= price then 
local a = tool:clone() 
a.Parent = player.Backpack
else 
end 
end 




script.Parent.MouseButton1Down:connect(buy) 
script.Parent.MouseEnter:connect(picture)

You also can remove the script. But I'd choose Debounce method instead.

3 comments

0

It's doesn't work,what should I do? D:

0

And yes, this is a normal script.

0

Oh great, the D in the Debounce Variable was uppercase, I changed it. Should work now. If not, then, either its a server script, else your original script doesn't work.

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