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

I need to detect body parts, not accessories. Help?

Asked by 4 years ago
Edited 4 years ago

I can't seem to find a way to detect R6 bodyparts. Help?

ToolDetector.Touched:Connect(function(hit)
    if hit.Parent.Name == "Left Leg" or "Right Leg" or "Torso" or "Right Arm" or "Left Arm" or "Head" then
        print(hit.Parent.Name.. " has touched the metal detector.")
        playerCharacter = hit.Parent
        hitPlayer = game.Players:FindFirstChild(hit.Parent.Name)
        loggedPlayer = game.Players:FindFirstChild(LoggedUser.Value)
        loggedGui = loggedPlayer.PlayerGui:FindFirstChild("MetalDetectorGui")
        playerBackpack = game.Players:FindFirstChild(hit.Parent.Name).Backpack

        loggedGui.username.Text = playerCharacter.Name
        for i, v in pairs(playerBackpack:GetChildren()) do   
            print(v)
           loggedGui.items.Text = "backpack: "..v..""
        end
    else
    end 
end)

The Whole Script:

--Settings
GroupID = 4994106
minimunRank = 0 -- Get the number of your role and subtract it by one.

-- ** Do not edit anything else further on. **
Body = {"Left Leg", "Right Leg", "Torso", "Right Arm", "Left Arm", "Head"}
Screen = script.Parent.Parent.Screen
ScreenClickDetector = Screen.ClickDetector
LoggedUser = script.Parent.LoggedUser
groupRank = ""
ScreenGui = script.Parent.MetalDetectorGui
ToolDetector = script.Parent.Parent.ToolDetector

ScreenClickDetector.MouseClick:Connect(function(player)
    groupRank = player:GetRankInGroup(GroupID)

    if groupRank <= minimunRank then
        print("'"..player.Name.."' has Attempted to log into a metal detector.")
    else
        local ScreenClone = ScreenGui:Clone()
        ScreenClone.Parent = player.PlayerGui
        LoggedUser.Value = player.Name
    end
end)

ToolDetector.Touched:Connect(function(hit)
    if hit.Parent.Name == "Left Leg" or "Right Leg" or "Torso" or "Right Arm" or "Left Arm" or "Head" then
        print(hit.Parent.Name.. " has touched the metal detector.")
        playerCharacter = hit.Parent
        hitPlayer = game.Players:FindFirstChild(hit.Parent.Name)
        loggedPlayer = game.Players:FindFirstChild(LoggedUser.Value)
        loggedGui = loggedPlayer.PlayerGui:FindFirstChild("MetalDetectorGui")
        playerBackpack = game.Players:FindFirstChild(hit.Parent.Name).Backpack

        loggedGui.username.Text = playerCharacter.Name
        for i, v in pairs(playerBackpack:GetChildren()) do   
            print(v)
           loggedGui.items.Text = "backpack: "..v..""
        end
    else
    end 
end)
1
You're checking the hit.Parents name, that would be the character. You have to check the hit's Name. hit.Name == "Left Leg", you could also use if hit:IsA("Part") then etc. That will check if hit is a part, not an accessory. killerbrenden 1537 — 4y
0
Thanks very much! loowa_yawn 383 — 4y

2 answers

Log in to vote
1
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 years ago

The reason your script isn't working is because you are checking if the hit's parent's name is equal to that of a body part. If it's a body part, it will only get the name of the actual Character.

Ad
Log in to vote
0
Answered by 1 year ago

welcome to the cringe-fest

ToolDetector.Touched:Connect(function(hit)
    -- simply check if the hit part is a valid child of a character model
    -- (this won't work for accessories, because accessories don't have humanoids inside of them)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then
        -- .. do stuff
    end 
end)

Answer this question