Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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)

01local touchingChar = false
02for _, 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
07                touchingChar = true
08                break
09            end
10        end
11    end
12end
13if 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.

0
again, .Touched function? zadobyte 692 — 4y
0
I don't really understand your question. Can I get a little more information and what you actually need? rabbi99 714 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
01local touchingChar do
02local EventConnections={}
03function touchingChar(char0,char1)
04local success,touchingParts=false,{}
05    for _,v0 in ipairs(char0:GetChildren())do
06        if v0:IsA"BasePart" then
07        for _,v1 in ipairs(char1:GetChildren())do
08            if v1:IsA"BasePart"and (v0.Position-v1.Position).magnitude<1.5 then success=true;touchingParts[#touchingParts+1]=v1 end
09        end
10        end
11        end
12        return success,#touchingParts>0 and touchingParts or nil
13        end
14end
15 
View all 22 lines...
Ad

Answer this question