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

New to lua, are limbs reference in hard code different for different character model? IE R6 vs R15

Asked by 6 years ago
Edited 6 years ago

Hey, so i've decided to start learning lua to add it to my scope of knowledge and practice for object oriented programming for game design. I've only recently started and it seems i've been learning some new and outdated stuff at the same time.

It seems I've been learning how to reference R6 Character models with Head, Torso, LeftArm, RightArm, LeftLeg, and RightLeg in code under the character Parent.

Torso and Head still seem to work fine but I don't know if that's because I'm testing with the original character 6 limb model. You know? The blocky lego one. I've never changed it haha.

I created an explosion on click tool that sets limbs on fire by creating a new fire instance under the limb parent Head and Torso but it seems the others mentioned before come up as not part of the character Parent. Could they be located elsewhere or is there another way to reference them?

The point of the tool is to set the limb on fire for about 5 seconds (Which is taken care of by the tool to create, apply, and destroy the fire instance) and apply damage based on distance from explosion and limbs hit (which i have the distance calculation already in the tool and fire damage is applied through a separate PlayerScript that constantly checks for fire on each limb to apply a different damage accordingly.)

This works for the Torso and Head so far, but I can't seem to figure out the code reference for the arms and legs.

I found this, but it either doesn't answer my question, or I just don't understand it haha https://devforum.roblox.com/t/r15-default-package-ids/73050

Here is my check for fire code:

while true do
    wait(.5)
    local TorsoBurn = script.Parent.Parent.Character.Torso:FindFirstChild("Fire")
    local HeadBurn = script.Parent.Parent.Character.Head:FindFirstChild("Fire")
    if TorsoBurn ~= nil or HeadBurn ~= nil then
        for i=1, 5 do
            TorsoBurn = script.Parent.Parent.Character.Torso:FindFirstChild("Fire")
            HeadBurn = script.Parent.Parent.Character.Head:FindFirstChild("Fire")
            if TorsoBurn ~= nil or HeadBurn ~= nil then
                if script.Parent.Parent.Character.Humanoid.Health > 0 then
                    script.Parent.Parent.Character.Humanoid:TakeDamage(10)          
                    print(script.Parent.Parent.Character.Humanoid.Health)
                    wait(1)
                end
            else
                break
            end
        end
        TorsoBurn:Destroy()
        HeadBurn:Destroy()
    else
    end
end

EDIT*

Forgot to mention, I added a print line of code into the tool to tell me what part is being hit and they do say Left arm, Right Arm, Left Leg, Right Leg. With the spaces as well. Not sure if that matters.

EDIT 2* So, I figure it out for my character.

script.Parent.Parent.Character:FindFirstChild("Left Arm")

this line of code works for my limbs I was originally using this:

script.Parent.Parent.Character.LeftArm
--or this
script.Parent.Parent.Character.Left_Arm

Would this work for any Character model?

2 answers

Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
6 years ago

In R15 you have "LeftFoot", "LeftHand", "LeftLowerArm", "LeftLowerLeg", "LeftUpperArm", "LowerTorso", etc etc

In R6 you just have "Left Arm", "Torso", etc

You can see these by pressing the play button and then going to workspace->yourName

To make things more easy, you could actually create a loop to do all these joints for you (there are a ridiculous amount of joints as you can tell)

local character = game.Players.LocalPlayer.Character

for _,part in pairs(character:GetChildren()) do
    if part:IsA("BasePart") then
        print(part.Name.." is a joint of your character")
    end
end

If you need to check for their RigType there's a property in Humanoid or you can test if the joints themselves exist

rig = character.Humanoid.RigType
if rig == Enum.HumanoidRigType.R15 then
    print("R15 character")
else
    print("R6 character")
end

--or

if character:FindFirstChild("UpperTorso") -- meaning R15 then
    print("Is an R15")
else -- meaning R6
    print("Is R6")
end

But in the end like I said, for future references you can just check workspace yourself to see what the parts are named or you could print the children

1
This helps a more than considerable amount! Thank you! I was always checking the Players folder and not the Workspace for the limbs. for some reason, it never occurred to me that the player parts would show up in Workspace... seems pretty obvious after having read that... HAHA ParanoiaZombie 3 — 6y
0
@ParanoidZombie approve his answer, please. bartekrabit 38 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

This script will never work unless you verify what rig the character has and then run a different set of code for each rig. The rigs in roblox are dramatically different because of how many joints the R15 rig has. If I were you I would find a part that each of them don't share with each other for each rig and make an if statement for finding it and then run a code that works for that specific rig. It should be pretty simple, just double the lines of code. Hope I helped

Answer this question