If statement for break conditional has been reach, loop still continues

I am making Momentum Running. I have made the direct running system work, through and proper. The issue reveals itself when I attempt to make a running dust trail whilst the character is running. I have a while true do loop, that breaks on a specific conditional.

Now, the way that the VFX Client gets this is from a FireServer, and two different inputs, being Began, and Ended which hold only true, and false, values that aren’t being changed actively on the client. So, what is happening is leaving me in utter confusion, and it’s not a direct issue related to the Server sending it over.

You see, I have a print inside of the if statement that leads to break, and even though it’s been printed multiple times previously, it’ll continue to play the loop as if the break never existed. Enough talking, here are the scripts.

if input == "W + W" then
		if Action and CooldownMod:CheckCD(Player, {"Running"}) == false and BattleModeActive == false then
			if IsSprinting then return end
			IsSprinting = true
			local AlreadyMax = false
			local Ran = 0
			local ShouldRun = false
			
			InputChecker = Inputs:Check(Enum.KeyCode.W, Player)
			Inputs:Insert(Enum.KeyCode.W, Player)
			
			
		
			Params = {Player = Player, Held = true}
			

			repeat task.wait(.5)
				Ran += 1
				if Character.Humanoid.WalkSpeed < MAX_SPEED then
					Character.Humanoid.WalkSpeed += 1

					print(Ran)
					if Ran >= 10 then
						if AlreadyMax then continue end
						AlreadyMax = true
						print("you dirty little boy you just keep printing")
						ServerE:FireServer(input, ActionClass, Action, Params)
					else
						AlreadyMax = false
					end
				end
			until IsSprinting == false or Character.Humanoid.MoveDirection.Magnitude == 0 or UserInputService:IsKeyDown(Enum.KeyCode.W) == nil
			
		

			
			Character.Humanoid.WalkSpeed = 13
			return
		end
	end

^InputBegan

if input == "W + W" then
		if IsSprinting == false then return end
		
		if IsSprinting then
			Character.Humanoid.WalkSpeed = 13
			
			Inputs:Remove(Enum.KeyCode.W, Player)
		
			Params = {Player = Player, Held = false}
			ServerE:FireServer(input, ActionClass, Action, Params)

			
			CooldownMod:CreateCooldown(Player, "Running", 1)
		
			return
		end
	end

InputEnded^

VFX Loop that is giving the issue in question

task.spawn(function()
		while true do
			if Held ~= true then print("bye") break end
			print("cryi' to dat ho", Held)
			local raycastResult = workspace:Raycast(arg[3].Position, RayDirection, RayParams)
			if raycastResult and raycastResult.Instance then
				
				if Held == false then break end
				DustClouds1.Color = ColorSequence.new(raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material), raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material))
				DustClouds2.Color = ColorSequence.new(raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material), raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material))
				DustClouds3.Color = ColorSequence.new(raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material), raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material))
				DustClouds4.Color = ColorSequence.new(raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material), raycastResult.Instance.Color or raycastResult.Instance:GetMaterialColor(raycastResult.Material))

				EmitAll(arg)	
			end
			task.wait(.10)
		end
		return
	end)

Print Debugs and Results:
image

I’m just boosting this up. I need it to be solved.

Checked back, and the error continues. It’s something about the loop, I don’t see that I’m setting the characters hold, but for some reason it’s getting set back to true.

Hi,
The VFX loop is run in a new thread each time it is called, so how is the Held variable being updated? As far as I can tell it is passed as an argument, meaning it wouldn’t update (just a new thread would get a different argument).

The release is meant to be the method of updating

unless I am misunderstanding you?

I removed the possible coroutine wraps, yet the issue still consists where it’ll change back, yet the FireServer is never called after the two presses.

You don’t provide all the relevant code so pretty much impossible to see where you’ve messed it up. Need to see what calls and starts the function, and the remoteevents that are supposed to stop it.

1 Like

I’ll make sure to do so for my next issue since I was able to solve it today.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.