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

Hit function not recognizing players body parts?

Asked by 7 years ago

Im trying to create a test tool that destroys another players body part when touched yet its not working and not giving me any errors, Any ideas?

local p = game.Players.LocalPlayer
local c = p.Character
local x = {"Right Arm", "Right Leg", "Torso", "Left Arm", "Left Leg", "Head"}
script.Parent.Touched:connect(function(hit)
    if hit.Parent ~= c then return end
        if hit.Parent == x then
            x:Destroy()

    end
end)

0
Is FilteringEnabled active? Goulstem 8144 — 7y
0
Yes dustyripjaw 2 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

You're actually missing an end on the innermost if statement. Also, your variable names aren't very descriptive. hit.Parent will never == x either, because x is a table. "connect" is deprecated, you should use Connect instead. :)

Instead, I recommend on doing this in a server-script inside game.ServerScriptService:

local part = workspace.Part
local debounce = true

local childrenToDestroy = {"Left Arm"}

part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if player then
        for _, characterChild in pairs(player.Character:GetChildren()) do
            for _, targetChild in pairs(childrenToDestroy) do
                if characterChild.Name == targetChild then
                    characterChild:Destroy()
                end
            end
        end
    end
end)

I'm assuming this is what you're trying to do but I'm not quite sure.

0
Thanks this helped alot dustyripjaw 2 — 7y
Ad

Answer this question