Why is my While statement not stopping when the test condition returns false?
Currently, I am having troubles with a while statement not ending properly when a condition isn't met. In whole, I am trying to make it so when the key "q" is pressed down, it sets "Held" to true then starting this loop and when it is pressed up, it turns "Held" to false and then stops this loop. I have confirmed through prints during these functions that it's working correctly.
01 | while Held = = true and wait() do |
02 | local debounce = false |
06 | local ray = Ray.new(char.Head.Position, char.Head.CFrame.lookVector * FireRange) |
07 | local part, endPoint = workspace:FindPartOnRay(ray, char) |
08 | local beam = Instance.new( "Part" ) |
09 | beam.FormFactor = "Custom" |
15 | beam.CanCollide = false |
16 | local distance = (char.Head.CFrame.p - endPoint).magnitude |
17 | beam.Size = Vector 3. new( 0.05 , 0.05 , distance) |
18 | beam.CFrame = CFrame.new(char.Head.CFrame.p, endPoint) * CFrame.new( 0 , 0 , -distance / 2 ) |
19 | beam.Parent = workspace |
20 | game:GetService( "Debris" ):AddItem(beam, ( 1 / 290 )) |
22 | local human = part.Parent:FindFirstChild( "Humanoid" ) |
23 | if human and ( not debounce) and (human.Parent ~ = char) then |
25 | char.Humanoid.Health = char.Humanoid.Health - . 066 |
Is this while statement not ending because the internals are somehow making it so it loops without checking the condition again? I have the whole loop inside a listener of the KeyDown event. If you are able to answer this, it would be appreciated if you left the issue and a solution.