For Loops not working in some scripts

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the for loop to work in the damage reciever

  2. What is the issue? Include screenshots / videos if possible!
    the damage reciever doesn’t work and I noticed it when it stopped playing the hurt animations and etc.

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

  • going to previous working versions and replacing the scripts.
  • reading over it again and again looking for the differences so I can figure out whats wrong but just can’t see it.
  • devforum for loop problems but they didn’t help much.
  • tried to see if the fighters tags were not being applied but they were.

This is the DamageReciever local script

local RS = game:GetService("RunService")
local CS = game:GetService("CollectionService")
local TS = game:GetService("TweenService")
local CharacterValues = require(game.ReplicatedStorage.Modules.CharacterValues)

local Fighters = CS:GetTagged("Fighter")
for _, Fighter in pairs(Fighters) do
	local character = Fighter
	local Humanoid = character:WaitForChild("Humanoid")
	local Animator = Humanoid:WaitForChild("Animator")

	local HurtAnim = Animator:LoadAnimation(script:WaitForChild("HurtAnimation"))
	HurtAnim.Priority = Enum.AnimationPriority.Action2
	
	local BlockAnim = Animator:LoadAnimation(script:WaitForChild("BlockAnim"))
	HurtAnim.Priority = Enum.AnimationPriority.Action4
	
	local ParryAnim = Animator:LoadAnimation(script:WaitForChild("ParryAnim"))
	HurtAnim.Priority = Enum.AnimationPriority.Action4
	
	local oldHealth = Humanoid.Health
	Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	
	if Humanoid.Health > oldHealth then
		oldHealth = Humanoid.Health print("Healed")
		
		return 
	end
	
		if Humanoid.Health > 1 and not character:GetAttribute("Parrying") and not character:GetAttribute("Blocking") then
		local OriginalWS = CharacterValues.CharacterValues.WalkSpeed
		Humanoid.WalkSpeed+= 3.5
		oldHealth = Humanoid.Health
		print("Damaged")
		
		HurtAnim:Play(0.2)
			TS:Create(Humanoid,TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(Random.new(3,-3),Random.new(3,-3),0)})
		task.delay(1, function()
			Humanoid.WalkSpeed = OriginalWS
		end)
	elseif Humanoid.Health > 1 and character:GetAttribute("Blocking") == true then
			BlockAnim:Play(0.2,1)
	elseif Humanoid.Health > 1 and character:GetAttribute("Parrying") == true then
			ParryAnim:Play(0.2,1)
	end
		
	end)
end

I did probably modify other scripts which could have caused this.
But testing it a few times I did get to have the damage reciever work without it having to change a code.
I’m probably forgetting a rule about LUA or something idk
But right now I need feedback on what I could do to fix this problem would really help A LOT.

You’re probably using return instead of continue.

return in loops will just cancel the whole loop.

3 Likes

As @Average_FreeTooPlay said you are using return inside of the for loops change them to continue.

I managed to get the thunderVolt working, turns out I was waiting for the sound to end but I already destroyed it by then.

I did try to switch the returns in some with continue, but I got the same result with the damage reciever.

One thing I did realize is that the scripts with for loops for the fighter tag just don’t work.

fixed it,

turns out the damage reciever was grabbing the tagged without anything being loaded meaning that
nothing had the fighter tag yet.

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