Hello!, Currently I’m doing a melee game and to detect hits I use a magnitude check on all player’s HumanoidRootParts and if they are in range I deal dammage to them (I know it’s bad since if 2 players are near then the player who is first inside the folder will get hit and not the closest, If you know a way to help me with this too then put it in it would be apreciated) So the problem comes when you dont want the system to detect yourself and deal dmg to yourself because you are close to the range so my solution was adding an if statement that compares the Character retrieved on the on the folder with the player who is firing the code and if they are the same it will ignore it and compare the rest of the folder until it finds one, But for some reason even if they arent the same it still ignores it.
Code:
– Raycast Attack function
local function CreateRayCastHitbox()
if RayCastAttack.Value then
for i, CharacterRetrieved in pairs(InGamePlayersFolder:GetChildren()) do
local DistanceBetweenCharacterRetrivedAndMyCharacter = (CharacterRetrieved.HumanoidRootPart.Position - MyCharacter.HumanoidRootPart.Position).Magnitude
print("DISTANCE",CharacterRetrieved.Name, DistanceBetweenCharacterRetrivedAndMyCharacter)
if DistanceBetweenCharacterRetrivedAndMyCharacter <= 10 and not CharacterRetrieved == MyCharacter then
print("HIT", CharacterRetrieved.Name)
RayCastRemote:FireServer(CharacterRetrieved.HumanoidRootPart)
return
else
print("EVENT DENIED", CharacterRetrieved.Name)
end
end
end
Output:
21:17:02.114 DISTANCE RespawningDummy 26.456268310547 - Client - FireAxeLocalScript:75
21:17:02.114 CCTVStudios - Client - FireAxeLocalScript:77
21:17:02.114 EVENT DENIED RespawningDummy - Client - FireAxeLocalScript:89
21:17:02.114 DISTANCE CCTVStudios 0 - Client - FireAxeLocalScript:75
21:17:02.114 CCTVStudios - Client - FireAxeLocalScript:77
21:17:02.114 EVENT DENIED CCTVStudios - Client - FireAxeLocalScript:89