I will try thanks for trying help
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HealthUIF = ReplicatedStorage.Events.AtobjClient
local HealthUIFr = ReplicatedStorage["Health Gui"]
local OldFr = nil
local DebounceA = false
-- use booleans for debounces
HealthUIF.OnClientEvent:Connect(function(Model, Debounce)
if DebounceA then
local CloneUI = HealthUIFr:Clone()
OldFr = CloneUI
return
end
-- exits if in debounce.
-- no need to wrap everything in an if statement
DebounceA = true
if OldFr then
OldFr:Destroy()
end
script.Parent.Handle.Beam.Attachment1 = nil
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
task.delay(1, function()
DebounceA = false
end)
end)
local MyModel = script.Parent
local PrimaryPart = MyModel.PrimaryPart
local ClickDetect = PrimaryPart:WaitForChild("ClickDetector")
local Debounce = false
local Stop = false
ClickDetect.MouseClick:Connect(function(clicker)
local character = clicker.Character
if Debounce then
character.Backpack.Handle.Beam.Attachment1 = nil
return
end
Debounce = true
character.Backpack.Handle.Beam.Attachment1 = PrimaryPart.Attachment
Stop = true
MyModel = script.Parent
print("Sucess")
print(MyModel)
if not script.Parent:FindFirstChild("Health Gui") 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)
if not Stop then break end
until Char.Backpack.EnergyC.Value > Char.Backpack.MaxCapacity.Value
if Stop then
Char.Backpack.EnergyC.Value = Char.Backpack.MaxCapacity.Value
Char.Backpack.Handle.Beam.Attachment1 = nil
end
task.delay(1, function()
Debounce = false
Stop = false
end)
end)
Geez, doing this on mobile is painful… Please check for errors first…
Also your script needs a bit of tidying up. I would do it but I’ve done enough on a phone screen.
it seems not working I tried it in my all script
well the booleans won’t fix the error; only make your code cleaner.
also did you add them for the compares?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.