Is it possible to stop a wait to countine if somthing chnaged like a number or not

Is it possible to stop a wait to countine if something changed like a number or not

1 Like

i want to stop a wait when a value is true and how can i do it

Well, you could use Value.Changed and if its changed to a certain number, you could set the change event to break the coroutine. Also, it’s really difficult to understand what your saying.

Let’s say that you press a key bind and I send a number through and then u wait for somthing to happen but u want to stop it and so u press the button again it stops but the wait part keeps going and so I want to stop it

Yes, But its dependent on the coroutine. If its a loop of sorts. Yes you can wait and yeild it. Yet alone even kill it. But if its just instructions, Then it can get complicated.

local IsEnabled = true
local IsActive = true

spawn(function() -- This is an example before people get mad i'm using 'spawn'
      while IsActive do
           repeat wait() until IsEnabled

           -- Execute Code
      end
end

alright so you don’t understand here this may help

game.ReplicatedStorage.Combat.Gripp.OnServerEvent:Connect(function(Player,HitPlayer,Debounce,count)
	if HitPlayer.Character.Humanoid.Health >= 0 then
		print(Debounce)	
		local Char = Player.Character
		print(HitPlayer)
		local HitChar = HitPlayer.Character
		if count >= 2 then
			anime2:Stop()
			anime:Stop()
		end	
		HitPlayer.Character.HumanoidRootPart.Anchored = false
		if count == 1 then
			anime = HitChar.Humanoid:LoadAnimation(script.HitPlayer)	
			anime2 = Player.Character.Humanoid:LoadAnimation(script.PlayerHit)
			game.ReplicatedStorage.Combat.Gripp1:FireClient(HitPlayer,HitPlayer)
			Char = Player.Character
			print(HitPlayer)
			HitChar = HitPlayer.Character
			HitPlayer.Character.HumanoidRootPart.Orientation = Vector3.new(89.9,HitPlayer.Character.HumanoidRootPart.Orientation.Y,HitPlayer.Character.HumanoidRootPart.Orientation.Z)
			Player.Character.Humanoid.WalkSpeed = 0
			Player.Character.Humanoid.JumpPower = 0	
			spawn(function()
				local health = HitChar.Humanoid.Health
				while true do
					wait()
					HitChar.Humanoid.Health = health
					print("E")
					if Debounce ==  true then
						break
					end
				end
			end)		
			for index, joint in pairs(HitPlayer.Character:GetDescendants()) do
				if joint:IsA("Motor6D") then
					joint.Enabled = true
				end
			end
			HitPlayer.Character.HumanoidRootPart.Anchored = true	
			HitPlayer.Character.RagDoll.Value = true
			HitPlayer.Character.Knocked.Value = true
			HitPlayer.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
			HitPlayer.Character.Humanoid.AutoRotate = false
			for i,v in pairs(HitPlayer.Character:GetDescendants()) do
				if v:IsA('BallSocketConstraint') then
					v:Destroy()
				end
			end
			for i,v in pairs(HitPlayer.Character:GetDescendants()) do
				if v:IsA('Attachment') then
					if v.Name == "Attachment" then
						v:Destroy()
					end
				end
			end
			HitPlayer.Character.HumanoidRootPart.Anchored = false
			anime:Play()
			anime2:Play()
				wait(3)		-- i want to stop this if count = 2
				print(count)	
				print("stop")
				if anime2.IsPlaying then
					Player.Character.Humanoid.WalkSpeed = 16
					Player.Character.Humanoid.JumpPower = 50
					HitChar.Humanoid.Health = 0
					anime:Stop()
				end 
			end)
		elseif count >= 2 then
			if HitPlayer.Character.Humanoid.Health >= 0 then
				Debounce = true
				Player.Character.Humanoid.WalkSpeed = 16
				Player.Character.Humanoid.JumpPower = 50
				anime2:Stop()
				HitPlayer.Character.HumanoidRootPart.Anchored = false
				anime:Stop()
				HitPlayer.Character.Humanoid.AutoRotate = false
				for index, joint in pairs(HitPlayer.Character:GetDescendants()) do
					if joint:IsA("Motor6D") then
						socket = Instance.new("BallSocketConstraint")
						a1 = Instance.new("Attachment")
						a2 = Instance.new("Attachment")
						a1.Parent = joint.Part0
						a2.Parent = joint.Part1
						socket.Parent = joint.Parent
						socket.Attachment0 = a1
						socket.Attachment1 = a2 
						a1.CFrame = joint.C0
						a2.CFrame = joint.C1
						socket.LimitsEnabled = true
						socket.TwistLimitsEnabled = true
						joint.Enabled = false
						HitPlayer.Character.HumanoidRootPart.Orientation = Vector3.new(89.9,HitPlayer.Character.HumanoidRootPart.Orientation.Y,HitPlayer.Character.HumanoidRootPart.Orientation.Z)
						HitPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
						HitPlayer.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
					end
				end
			end
		end
	end
end)