Monday, May 25, 2020

Roblox | How to make a Pet System!

A few months ago, if not a year, i uploaded a video giving a tutorial on making pets. I do read your comments, every single one, and some were not really getting the gist on how the process works. This time, i've made a brand new tutorial on how you can model your pets and making the system in general. I hope this tutorial helps you. Also, i uploaded the model that i made along with open-source code to Roblox which you can get here: https://www.roblox.com/library/4851551035/Amirs-Pet-Sample Now, for those who want to know how the system works, i will tell you from the FollowScript first. 1. The FollowScript Now in the video i've told you to Disable the script. Why? Because i didnt want the script to run immediately and cause an error. Sure it will be cloned and parented with everything being normal, but it just makes a clutter in the output. On with the code, i reference the Base as the parent of the script, simple stuff, and the "heart" variable is what the base will use to get an appropriate Position to follow the character. In this case, the pet will be floating around the players "Head". Next, you may have not heard of RunService before. If you havent, you can learn about it here "https://developer.roblox.com/en-us/api-reference/class/RunService". In simple words, you can run a function every single time it gets the opportunity. And we want to set the values as often as we can so the pet is constantly following the player, hence the usage of RunService. Now we run across BodyGyro and BodyPosition. These are what we call BodyMovers. They can move and rotate a part in a set amount of Force. We can use BodyGyro to make a part maintain a set rotation (using its CFrame property). While BodyPosition is about self-explanatory, it maintains a parts position. You may be confused as to what CFrames are. You might not know the difference between CFrames and Vector3. You can read all about CFrames here "https://developer.roblox.com/en-us/articles/Understanding-CFrame". CFrames are what i am using to set the values of the BodyGyro and BodyPosition. The reason i put ".p" at the end of the BodyPositions value is because the BodyPosition does not accept CFrames as their value. So id have to return a position (In other words Vector3) to prevent errors. 2.The Script in ServerScriptService This one is alot more simple than the other one. What we're doing is simple collecting signals when a character is loaded into the game. After that, we put the pet inside said character and turn on the script. Simple as that. Now i doubt any of you will read this but its nice to make an article about how my code works. I like teaching, it makes me feel smarter, which i am haha. Thank you for watching.


Roblox | How to make a Pet System!

No comments:

Post a Comment