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

What do I do?

Asked by
duckyo01 120
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I just used this script so that when you have your right arm off you go through the door but when I have my left arm and right arm off I still go through the door. Is there anyway to fix that?

This is the code.

local part = script.Parent

part.Touched:connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = hit.Parent

        if not player:FindFirstChild("Right Arm") then
            part.CanCollide = false
            part.Transparency = 0.6

            wait(2)

            part.Transparency = 0

        else
            local humanoid = player:FindFirstChild("Humanoid")

            if humanoid then
                humanoid:TakeDamage(humanoid.Health)
            end
        end
    end
end)

2 answers

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

You pretty much have it down, you just need to add another condition that checks if the left arm is there or not. To do that, we'll pretty much do what you already have, and just check both arms.


Your script should look like this:

local part = script.Parent

--[]

--Change the ones that need to be OFF to true
--Change the ones that need to stay ON to false
local LeftArm = false
local RightArm = true
local LeftLeg = false
local RightLeg = false

--[]

function CheckLimbs(player)
    local CheckCount = 0
    if (LeftArm == true and not player:FindFirstChild("Left Arm")) or (LeftArm == false and player:FindFirstChild("Left Arm")) then
        CheckCount = CheckCount+1
    end
    if (RightArm == true and not player:FindFirstChild("Right Arm")) or (RightArm == false and player:FindFirstChild("Right Arm")) then
        CheckCount = CheckCount+1
    end
    if (LeftLeg == true and not player:FindFirstChild("Left Leg")) or (LeftLeg == false and player:FindFirstChild("Left Leg")) then
        CheckCount = CheckCount+1
    end
    if (RightLeg == true and not player:FindFirstChild("Right Leg")) or (RightLeg == false and player:FindFirstChild("Right Leg")) then
        CheckCount = CheckCount+1
    end
    if CheckCount==4 then
        return true
    else
        return false
    end
end

part.Touched:connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = hit.Parent

        if CheckLimbs(player) then
            part.CanCollide = false
            part.Transparency = 0.6

            wait(2)

            part.Transparency = 0

        else
            local humanoid = player:FindFirstChild("Humanoid")

            if humanoid then
                humanoid:TakeDamage(humanoid.Health)
            end
        end
    end
end)

So now it should work how you wanted. If you have any further problems or questions, leave a comment below, and I'll see what I can do. Hope I helped :P

-Dyler3

Ad
Log in to vote
-1
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
local part = script.Parent

part.Touched:connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = hit.Parent

        if not player:FindFirstChild("Right Arm") and player:FindFirstChild("LeftArm") then
            part.CanCollide = false
            part.Transparency = 0.6

            wait(2)

            part.Transparency = 0

        else
            local humanoid = player:FindFirstChild("Humanoid")

            if humanoid then
                humanoid:TakeDamage(humanoid.Health)
            end
        end
    end
end)

Here.

Answer this question