Error with If Statement I believe

Trying to make a simple jab, although I’m getting an error about the if statement… Heres my code:

local Event = game.ReplicatedStorage.CombatEvents.Jab




game.ReplicatedStorage.CombatEvents.Jab.OnServerEvent:Connect(function(Player, Action)
	local c = Player.Character
	if Action == "Jab1" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then
		
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then
						
						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(1)
						CurrentDamage.Value += 1
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						v.Conditions.IsAttacking.Value = false
					elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
						if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
							v.Conditions.IsAttackedWhileBlocking.Value = true
						end
					end
				end
			end
		end
		
		
		
	elseif Action == "Jab2" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then
		
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then
						
						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(2)
						CurrentDamage.Value += 2
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						v.Conditions.IsAttacking.Value = false
					elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
						if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
							v.Conditions.IsAttackedWhileBlocking.Value = true
						end
					end
					end
				end
			end
		end
		
		
		
	elseif Action == "Jab3" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then
		
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then
						
						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(3)
						CurrentDamage.Value += 3
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						
						local Force = Instance.new("BodyVelocity")
						Force.Parent = v.HumanoidRootPart
						Force.MaxForce = Vector3.new(5000, math.floor(math.random(50,200)), 0)
						CurrentDamage.Value += 125
						Force.Velocity = c.HumanoidRootPart.CFrame.LookVector * CurrentDamage.Value*2
						print(Force.Velocity)
						game.Debris:AddItem(Force, 0.3)
					v.Conditions.IsAttacking.Value = false
				elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
					if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
						v.Conditions.IsAttackedWhileBlocking.Value = true
					end
				end
						
					end
				end
			end
		end
	end
end)

Please help!

What is the error? That would give us a better idea as to how to approach the problem.

1 Like

The error is " Expected ‘end’ (to close ‘function’ at line 6), got ‘elseif’; did you forget to close ‘then’ at line 52?"

You have 2 too many ends.

local Event = game.ReplicatedStorage.CombatEvents.Jab




game.ReplicatedStorage.CombatEvents.Jab.OnServerEvent:Connect(function(Player, Action)
	local c = Player.Character
	if Action == "Jab1" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then

		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then

						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(1)
						CurrentDamage.Value += 1
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						v.Conditions.IsAttacking.Value = false
					elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
						if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
							v.Conditions.IsAttackedWhileBlocking.Value = true
						end
					end
				end
			end
		end



	elseif Action == "Jab2" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then

		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then

						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(2)
						CurrentDamage.Value += 2
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						v.Conditions.IsAttacking.Value = false
					elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
						if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
							v.Conditions.IsAttackedWhileBlocking.Value = true
						end
					end
				end
			end
		end
	end



	elseif Action == "Jab3" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then

	for i, v in pairs(game.Workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
			local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
			if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
				if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then

					v.Conditions.IsAttacking.Value = true
					local CurrentDamage = v.Conditions.CurrentDamage
					v.Humanoid:TakeDamage(3)
					CurrentDamage.Value += 3
					if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
						v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
					end

					local Force = Instance.new("BodyVelocity")
					Force.Parent = v.HumanoidRootPart
					Force.MaxForce = Vector3.new(5000, math.floor(math.random(50,200)), 0)
					CurrentDamage.Value += 125
					Force.Velocity = c.HumanoidRootPart.CFrame.LookVector * CurrentDamage.Value*2
					print(Force.Velocity)
					game.Debris:AddItem(Force, 0.3)
					v.Conditions.IsAttacking.Value = false
				elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
					if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
						v.Conditions.IsAttackedWhileBlocking.Value = true
					end
				end

			end
		end
	end
end)
1 Like

I’m still getting an error… :sob:
I used your code yet I still got an error, even though I corrected the mistake you made for the if statement, what should I do now?!

you only have 1 too many ends, not 2.

game.ReplicatedStorage.CombatEvents.Jab.OnServerEvent:Connect(function(Player, Action)
	local c = Player.Character
	if Action == "Jab1" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then

						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(1)
						CurrentDamage.Value += 1
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						v.Conditions.IsAttacking.Value = false
					elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
						if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
							v.Conditions.IsAttackedWhileBlocking.Value = true
						end
					end
				end
			end
		end
	elseif Action == "Jab2" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then

						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(2)
						CurrentDamage.Value += 2
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						v.Conditions.IsAttacking.Value = false
					elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
						if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
							v.Conditions.IsAttackedWhileBlocking.Value = true
						end
					end
				end
			end
		end
	elseif Action == "Jab3" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then
						v.Conditions.IsAttacking.Value = true
						local CurrentDamage = v.Conditions.CurrentDamage
						v.Humanoid:TakeDamage(3)
						CurrentDamage.Value += 3
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.Value .. "%"
						end
						local Force = Instance.new("BodyVelocity")
						Force.Parent = v.HumanoidRootPart
						Force.MaxForce = Vector3.new(5000, math.floor(math.random(50,200)), 0)
						CurrentDamage.Value += 125
						Force.Velocity = c.HumanoidRootPart.CFrame.LookVector * CurrentDamage.Value*2
						print(Force.Velocity)
						game.Debris:AddItem(Force, 0.3)
						v.Conditions.IsAttacking.Value = false
					elseif (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 and v.Conditions.IsBlocking.Value == true then
						if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
						v.Conditions.IsAttackedWhileBlocking.Value = true
						end
					end
				end
			end
		end
	end
end)
1 Like

What is the new error? If possible, provide it each time.

1 Like

Same thing as before, I made sure to correct the mistake you made too

Let me try it, hope it works…

1 Like

Thank you! It works, I can finally get back to working on some other mechanics and not worry about the error crashing my script, thanks again! :slightly_smiling_face: