Function executing multiple times

Hello, I currently have a problem: I created a function used to buy objects,
The problem is that if I buy an item several times, each time the price will be doubled, but I don’t want that.
Thanks to anyone who can help me :slight_smile:

Server Script:

repeat wait()
					print(game.ReplicatedStorage.BuyDialog)
					until game.ReplicatedStorage.BuyR.OnServerEvent:Connect(function(Buy)
						
						if Buy then
							
						money.Value = money.Value - 20
						AxeBox.Owner.Value = player.Name
							AxeBox.Parent = workspace
							NewDialog:Destroy()
							hit.Parent.Name = "WoodenAxeBox Owned"

Local Script :

if leaderstats.Money.Value >= 20 then
			RemoteEvent:FireServer(Buy)
				script.Disabled = true
				script.Disabled = false

try changing this to:

:Once(function(Buy)

so it only triggers once

1 Like

Thank you so much, it worked!
I’ve been looking for a long time :')

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.