Script doesn't detect the right player?
Asked by
4 years ago Edited 4 years ago
So what I'm trying to do is to make a function that only happens when the enemy player is touching the stunned player.
Unfortunately my method of detecting it doesn't work for some reason:
(char
is the stunned player's character and player
is the enemy player)
01 | local touchingChar = false |
02 | for _, bodyPart in pairs (char:GetChildren()) do |
03 | if bodyPart:IsA( "BasePart" ) then |
04 | for _, part in pairs (bodyPart:GetTouchingParts()) do |
05 | local hum = part.Parent:FindFirstChild( "Humanoid" ) |
06 | if hum and Players:GetPlayerFromCharacter(part.Parent) = = player then |
13 | if not touchingChar then return end |
Please help!
EDIT: This function only fires when the enemy player presses a key, so I need to know if he's touching the stunned player at that very moment.