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?
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
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