Triple hatch system costing more when click fast

Hey there!

So, i’ve been facing problems with a thing im doing.

Alright, so let me make an example;
I use the hatching system, i pick triple hatch because i have enough for it, it works perfectly and takes the perfect amount. Now i try to hatch again, works perfectly fine and takes the perfect amount again, but then i hatch the third time, and it works perfectly fine but with a twist, it takes double the amount now. So if it costed 18k, now it would take 36k.

Now, i don’t know when it takes double and also the example actually happened, the only reason i know this happens is cause this happened two times.

I don’t know why this is happening but, maybe it’s the fact i use a remote function.

Heres the code;

Server:

EggCheck3.OnServerInvoke = function()
					local e2 = egg.Cost.Value*2
					if Player.Coins.Value >= e2 then
						return true
					else
				Rep.DisplayMessage:FireClient(Player, tostring("You need "..e2 - Player.Coins.Value.." Coins to open this egg!"), "Message")
					end
				end
 
				Rep.DisplayHatchOptions:FireClient(Player, egg.EggName.Value, egg.Cost.Value, RandomPet,"Golden","Coins")
				wait(3)
				Rep.HatchCost.OnServerEvent:Connect(function(player,ID,op)
					print(ID)
					if ID == "Egg1" then
						print(op)
						if op == 1 then
							Player.Coins.Value -= egg.Cost.Value
						elseif op == 3 then
							local e = egg.Cost.Value*2
							print(e)
							Player.Coins.Value -= e
						end
					end
				end)

Client:

DisplayHatchOptions.OnClientEvent:Connect(function(EggName,Cost,Pet,Type,Currency,ID)
	local TripleMsgClone = TripleHatchMsg:Clone()
	local desc = TripleMsgClone.Frame.Desc
	local buy3 = TripleMsgClone.Frame.Option2
	local buy1 = TripleMsgClone.Frame.Option1
	local cancel = TripleMsgClone.Frame.Cancel
 
	desc.Text = ("Buy and open a ".. EggName .. " for " .. Cost .. " " ..Currency)
	TripleMsgClone.Parent = PlayerGui
 
	buy1.MouseButton1Click:Connect(function()
		Rep.HatchCost:FireServer(EggName,1)
		Debris:AddItem(TripleMsgClone,0.1)
		hatch(Pet,Type)
	end)	
 
	buy3.MouseButton1Click:Connect(function()
		local yesnt = Rep.EggCheck3:InvokeServer()
		if yesnt == true then
			Rep.HatchCost:FireServer(EggName,3)
			Debris:AddItem(TripleMsgClone,0.1)
			hatch(Pet,Type)
			wait()
			hatch(Pet,Type)
			wait()
			hatch(Pet,Type)
		end
	end)
 
	cancel.MouseButton1Click:Connect(function()
		Debris:AddItem(TripleMsgClone,0.1)
	end)
end)

Edit: I found out the possible reason, i haven’t really tested if it happens randomly or when i click fast. When i click triple hatch (or even single hatch) triple hatch is only supposed to cost double the amount of single hatch, (single hatch is 9k) but instead of costing 18k, it costs a lot more. The reason why (i tested a bit) is that if i click “triple hatch” more than once, it costs a lot more than 18k.

I could easily fix it by using a Debounce, but anything i did hasn’t worked, any ideas on how i could make a debounce work?

Thanks :smiley:

1 Like

Hello, I’m not sure what you need help with, but if you mean the 3rd egg is taking double while it isnt supposed to, its because your doubling the value in the server script:
local e = egg.Cost.Value*2

1 Like

My apologies for being so confusing, original price is 9k, so the game takes 9k if the player uses one hatch only, but if the player takes 3 hatch, it takes 18k. But somehow after using 3 hatch 3 times, that 18k becomes 36k which is not supposed to happen.

A debounce would work by first doing:

local debounce = false

Then before the whole buying happens, check if debounce == false, if it is, continue your script but write debounce = true, so that it wont work anymore since its true not false now. Then, in the end, you could do for example wait(10) then setting debounce back to false.

1 Like