Making old tools work with R15
Making old tools work with R15
This is a step by step example of how to convert a tool to work with both R6 and R15.
- Pick a tool to convert. For this example I chose Sword of the Epicredness.
- Open an R15 place in Roblox Studio. It’s good to have an empty place so it’s easier to search through the gear’s scripts.
- Insert the tool using InsertService by running this script in the command bar
local id = 409745306 game:GetService("InsertService"):LoadAsset(id):GetChildren().Parent = game.Workspace
The gear should be in the Workspace. Use the toolbox to insert a few zombies in the game that we can test the sword on. Press F5 or click the Play button to test locally. After your character spawns, pick up the gear and test it. When I click with my left mouse button, I can see that the sword is not slashing as it is supposed to.
Open up the Output window in Studio to see if the gear is throwing any errors. If there are errors in the output, they might tell us which parts the script is relying on that don’t exist in R15. In this case, there are no errors in the output. Many scripts rely on the existence of parts named “Torso” or “Right Arm” in the character in order to function. That is probably what is causing the sword to break.
Fixing Old Part Names
Stop the game and search all scripts in the game for the word “Torso” by pressing Ctrl Shift F and typing Torso into the search box.
- Double click on each file to open. You can see this line:
local torso = character:FindFirstChild("Torso")
- We can see that the script relies on “Torso” existing. This won’t work for R15 because Torso has been split up into UpperTorso and LowerTorso.
- To make this work for both R6 and R15, we can take advantage of the fact that FindFirstChild returns nil if the item does not exist. We can add this snippet of code on the end of our line that falls back to UpperTorso if Torso is nil.
local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
After updating all places that use Torso to use UpperTorso as a fallback, let’s test the gear again. Run the game, pick up the sword and click to attack a zombie. Now we can see that the mouse icon changes correctly when you click, but nothing else happens. Maybe the gear checks if the “Right Arm” exists, let’s do the same search earlier only for Right Arm. You find this code snippet:
local RightArm = Character:FindFirstChild("Right Arm") if not RightArm then return end
Let’s correct it in the same way that we corrected torso earlier, by falling back to “RightHand”
local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand") if not RightArm then return end
I’m going to test again. This time, when I run up and click while I’m touching the zombie, my sword does damage!
The last thing to fix is the animations. Usually when I use a sword, my character has a swing animation. Opening the tool we see that the tool has a set of animations. However, they were made for the R6 character, so the animations contain no data about how to control an R15 character.
I’m going to click on each animation and update the AnimationId with the ID of a new version of the animation I made that has animation for each part. This makes the animations work for R15, but means that they won’t work for R6. To make them work for both types, we need to have two animations and detect the avatar type using Humanoid.RigType in the script. That’s not covered here yet.
Testing once more, I can see that the animation works. We’re done!