Help comparing positions and getting the lowest one

Hello, I’m attempting to compare another player with two positions, one slightly in front of the local player’s root part, and one behind.

Code:

I’ve been trying to stop ending up with the same value after getting the magnitude of the two positions but I’m having no luck. Any help will be appreciated thank you for your time!

The way you set up your code, FrontComparison/BackComparison will never change even if you move the character around.

What are you trying to do exactly? Why do you need to compare between the front and back?

1 Like

I’m creating a blocking system, when a player blocks attacks from the front are supposed to be blocked, and attacks coming from behind the player do not get blocked and damages the player.

This is my updated code:

I’m having trouble with the “frontComparison” and the “backComparison” variables, as “frontComparison” is always less than “backComparison” even when attacking a blocking player from behind.

Basically I’m trying to figure out which CFrame the enemy is closer to when attacking the blocking player

Ok, I figured. It’s an easy fix.

Earlier in your code you set the attacker as your own character.

In your updated code, I see you changed it, but it’s bad now. You’ve got your blocking code backwards.
image

Thing is defending here, but you’re having it be the attacker also.
You should update your variables to track the correct characters:

  • attackerPosition should track char
  • frontCFrame should track thing.Parent
  • backCFrame should track thing.Parent
  • everything else keep the same

Naming variables properly is important or you’re going to confuse yourself with who’s doing what.

1 Like

Sheesh yeah I really have to be careful, I probably shouldn’t name stuff “thing” cause I REALLY got tangled on what everything was lol. Thanks so much!

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