Multiple issues with purchase script

Hey guys! I have multiple issues with a purchase script I made today. This script is located in the top of the button and is a server script. Issue 1: This is the main one I want to get fixed, Basically when the “Dogestage” Increases the script stops working but the doge does spawn. I will explain more in the actual script. Issue 2: For some reason it takes about 8 seconds of running on the button for it to register and work. I have no clue why. Issue 3: The cost increases incorrectly. In the script it seems as it would go 0, 8, 16, 24, 32 and so on but it actually goes 0, 8, 24, 48. I have absolutely no clue why this happens and yes I checked the value of Dogecount and it is normal. If you have any idea to why any of these could be happening please let me know. Script located in the button. (Sorry if its messy) Here’s the script:

local Doge = game.ServerStorage.Doge
local FancyDoge = game.ServerStorage.FancyDoge
local cost = script.Cost
local Button = script.Parent
local deb = false

Button.Touched:Connect(function(hit)
	if deb == false then
		deb = true
		if hit.Parent.Parent.Name == "Workspace" then
			local char = hit.Parent
			local plr = game.Players:GetPlayerFromCharacter(char)
			local Dogestage = plr.Dogestage
			
			if plr.leaderstats.Cash.Value >= cost.Value then
				plr.leaderstats.Cash.Value -= cost.Value
				if plr.Dogecount.Value < 10 then
					if Dogestage.Value == 0 then
						local DogeClone = Doge:Clone()
						local PreparedValue = plr.Dogecount.Value * 9
						local CloneX = 40.5 - PreparedValue
						DogeClone.Parent = game.Workspace.Area1.Doges
						DogeClone.CFrame = CFrame.new(CloneX, 9, 95.5)
						plr.Dogecount.Value += 1
						cost.Value += plr.Dogecount.Value * 8--Cost problem here.
					elseif Dogestage == 1 then
						local DogeClone = FancyDoge:Clone()
						local PreparedValue = plr.Dogecount.Value * 9
						local CloneX = 39.85 - PreparedValue
						DogeClone.Parent = game.Workspace.Area1.Doges
						DogeClone:PivotTo(CFrame.new(CloneX, 12.316, 94.858))
						plr.Dogecount.Value += 1
						cost.Value += plr.Dogecount.Value * 20
					end
				else
					Dogestage.Value += 1--This is the part that works normally but then whole script breaks after its finished.
					plr.Dogecount.Value = 0
					game.Workspace.Area1.Doges:ClearAllChildren()
					if Dogestage.Value == 1 then
						local PreparedValue = plr.Dogecount.Value * 9
						local CloneX = 39.85 - PreparedValue
						local DogeClone = FancyDoge:Clone()
						DogeClone.Parent = game.Workspace.Area1.Doges
						DogeClone:PivotTo(CFrame.new(CloneX, 12.316, 94.858))
						plr.Dogecount.Value += 1
						cost.Value += plr.Dogecount.Value * 20
					end
				end
			else
				Button.Color3 = Color3.new(255, 0, 0)
				wait(0.5)
				Button.Color3 = Color3.new(0, 255, 0)
			end
		end
		wait(1)
		deb = false
	end
end)

You’ve replied to countless posts this quickly already. I strongly believe that misleading people with ChatGPT code is not right, worse because you didn’t even bother to check the code before just pasting it.

Please think about what you’re doing.

Sorry about that cause sometimes it works fine

If you want to help, do it properly. If you want to use ChatGPT go ahead, but at least use your brain to at least read the code and try to “compile” it in your head to see if it actually works.

You don’t just paste in “what’s the issue with this lua code {code}”, then immediately copy the answer. Come on, think about it.

And delete your other posts please.

1 Like