Look at the bottom and you can see I clearly disconnect it, yet it still keeps going:
pcall(function()
airConnection = game:GetService("RunService").Stepped:Connect(function()
if not char or not v or hum.Health == 0 or v.Parent.Humanoid.Health == 0 then airConnection:Disconnect()
char:SetAttribute("InAir", false)
print("changed from stupid air connection")
if char.HumanoidRootPart:FindFirstChild("AlignPosition") then
char.HumanoidRootPart:FindFirstChild("AlignPosition"):Destroy()
end
end
if tick() - lastAirAttack >= 1 then
if v.Parent.HumanoidRootPart:FindFirstChild("AlignPosition") and char:GetAttribute("HyperArmor") then
v.Parent.HumanoidRootPart:FindFirstChild("AlignPosition"):Destroy()
end
if char.HumanoidRootPart:FindFirstChild("AlignPosition") and char:GetAttribute("HyperArmor") then
print("deletedFromAirAttack")
char.HumanoidRootPart:FindFirstChild("AlignPosition"):Destroy()
end
airConnection:Disconnect()
char:SetAttribute("InAir", false)
v.Parent:SetAttribute("InAir", false)
print("Changed from air attack connection STIILL")
end
end)
end)
Using :Disconnect() won’t halt the event from continuing to run further, if that is what you meant.
Instead, it would essentially stop watching the event, meaning it won’t run anymore after.
Instead, you could use “return” to stop further execution after you have disconnected the event if that is what you are after. Make sure you disconnect before you use return.
pcall(function()
airConnection = game:GetService("RunService").Stepped:Connect(function()
if not char or not v or hum.Health == 0 or v.Parent.Humanoid.Health == 0 then airConnection:Disconnect()
char:SetAttribute("InAir", false)
print("changed from stupid air connection")
if char.HumanoidRootPart:FindFirstChild("AlignPosition") then
char.HumanoidRootPart:FindFirstChild("AlignPosition"):Destroy()
end
end
if tick() - lastAirAttack >= 1 then
if v.Parent.HumanoidRootPart:FindFirstChild("AlignPosition") and char:GetAttribute("HyperArmor") then
v.Parent.HumanoidRootPart:FindFirstChild("AlignPosition"):Destroy()
end
if char.HumanoidRootPart:FindFirstChild("AlignPosition") and char:GetAttribute("HyperArmor") then
print("deletedFromAirAttack")
char.HumanoidRootPart:FindFirstChild("AlignPosition"):Destroy()
end
char:SetAttribute("InAir", false)
v.Parent:SetAttribute("InAir", false)
print("Changed from air attack connection STIILL")
airConnection:Disconnect()
return
end
end)
end)
What is the intended behaviour here? Where in the code do you expect further execution to stop? What I mean by this is how are you testing it, because I see two disconnect calls within the connection itself, so I was wondering what conditions you are creating during testing.
Well I made it so that it will fire a different event to this when InAir is true, but this keeps making InAir false since i for some reason cant disconnect it