Unable to solve execution error

Hello, I added debounce and “is it exists” check but it still gives the error, Idk how I solve that

Screenshot_10

The script gives the error

local HealthUIF = game.ReplicatedStorage.Events.AtobjClient
local HealthUIFr = game.ReplicatedStorage["Health Gui"]
local OldFr = nil
local DebounceA = 0

HealthUIF.OnClientEvent:Connect(function(Model, Debounce)
	if DebounceA == 0 then
		DebounceA = 1
		if OldFr ~= nil then
		OldFr:Destroy()
		end	
		script.Parent.Handle.Beam.Attachment1 = nil
			if Debounce == 1 then
				local CloneUI = HealthUIFr:Clone()
				OldFr = CloneUI
			if not Model.PrimaryPart:FindFirstChild("Health Gui") then
				CloneUI.Parent = Model.PrimaryPart
			end
				
				CloneUI.Placed.Value = true
			script.Parent.Handle.Beam.Attachment1 = Model.PrimaryPart.Attachment
	    end
		DebounceA = 0
	end
	
end)

The script triggers the error script

local MyModel = script.Parent
local PrimaryPart = MyModel.PrimaryPart
local ClickDetect = PrimaryPart:WaitForChild("ClickDetector")
local Char
local Debounce = 0


local Stop = 0

ClickDetect.MouseClick:Connect(function(clicker)


	Char = clicker.Character
	if Debounce == 0 then
		Debounce = 1
		Char.Backpack.Handle.Beam.Attachment1 = PrimaryPart.Attachment
		Stop = 1
	else
		Debounce = 0
		Char.Backpack.Handle.Beam.Attachment1 = nil
		Stop = 0
	end    
		MyModel = script.Parent
		print("Sucess")
			print(MyModel)
			if script.Parent:FindFirstChild("Health Gui") == nil then
				game.ReplicatedStorage.Events.Atobj:Fire(clicker)
	    		game.ReplicatedStorage.Events.AtobjClient:FireClient(clicker, MyModel, Debounce)
			end
		
	repeat
		if MyModel.Energy.Value < 0 then
			MyModel:Destroy()
		end
		MyModel.Energy.Value -= Char.Backpack.Attack.Value
		Char.Backpack.EnergyC.Value += Char.Backpack.Attack.Value
		wait(Char.Backpack.AttackRate.Value)
	
		
	until Stop == 0  or Char.Backpack.EnergyC.Value > Char.Backpack.MaxCapacity.Value
	if Stop == 1 then
		Char.Backpack.EnergyC.Value = Char.Backpack.MaxCapacity.Value
		Debounce = 0
		Char.Backpack.Handle.Beam.Attachment1 = nil
		Stop = 0
	end
	


	
end)

try putting wait() in the repeat loop?

This not a loop this a function

Oh there is some repeat function but it about this lines

				game.ReplicatedStorage.Events.Atobj:Fire(clicker)
	    		game.ReplicatedStorage.Events.AtobjClient:FireClient(clicker, MyModel, Debounce

How many times do you fire the MouseClick event before you start receiving this error? You might want to add a debounce in the MouseClick event instead of the OnClientEvent. Are you sure there isn’t any other script that could also be firing the same MouseClick event?

I am talking about this:

To fix it, just put a wait into it:

	repeat
		if MyModel.Energy.Value < 0 then
			MyModel:Destroy()
		end
		MyModel.Energy.Value -= Char.Backpack.Attack.Value
		Char.Backpack.EnergyC.Value += Char.Backpack.Attack.Value
		wait(Char.Backpack.AttackRate.Value)
	
		wait()
	until Stop == 0  or Char.Backpack.EnergyC.Value > Char.Backpack.MaxCapacity.Value

The wait slows the repeat script down so roblox has time to run it. Before this, the script went way too fast for roblox to handle, therefore it errors.

by the way, it doesnt slow it down too much, it slows it down by a few milliseconds.

Screenshot_13

“I’m a function” printed when entity clicked it seems fired 1 time but execution time error fired a lot

I’m a little confused, I thought the error was occurring from the LocalScript, but it appears you are now showing the error occurring from the server script. Also, what is the exact line you are receiving this error from?

have you tried using my fix? (Chars)

Screenshot_14
it directs me to my local script last line

yes but it not works and this repeat script works great (Energy decreasing in model successfully)

which script is local? (Charssss)

The script first I wrote (it about health GUI cloning)

and what is line 18? im asking because you may have not posted the full script.

is it the line of 18 in my local script

Can you maybe show the whole script or where line 18 is

it’s already whole script maybe it can be another script line 18

I know this isn’t directly related to the error, but have you heard about Booleans?

yes I heard about booleans (I try find error in other scripts related error)

you know the part of the script where you declare true / false values as ones and zeros, you should really use booleans instead.