Hello, I added debounce and “is it exists” check but it still gives the error, Idk how I solve that
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)
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?
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.
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?