(This is my first tutorial! There might be a few issues about how I word it!)
Tired of these small avatars ruining hitboxes for your games?
Well, you’ve come to the right place.
heres the backstory on why i did this and all code after
I was playing Doomspire Brickbattle today with a friend of mine and saw 2 small avatar players. I mean, its fine if you want a small avatar, but to gain a competetive advantage? No thank you! I left the game shortly after, but that gave me an idea;
How can I get rid of these small avatars?
So I started brainstorming.
You’re just here for the code right? Here it is.
-- Put this script in ServerScriptService or Workspace!
local normalYSize = 4.65 --i recommend setting this a bit higher than the height of a normal avatar with all size settings cranked down
local armParts = {
"UpperArm",
"LowerArm",
"Hand"
}
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
--get player's avatar as a model for size comparison
local model = game.Players:CreateHumanoidModelFromUserId(plr.UserId)
if model:WaitForChild("Humanoid").RigType == Enum.HumanoidRigType.R6 then model:Destroy() return end
-- ugc characters only work in r15 (unless they're dynamic heads)
for _, part in model:GetChildren() do
if part:IsA("Accessory") then
part:Destroy()
end
end
print("needs check")
model.Parent = workspace
model.PrimaryPart.CFrame = CFrame.new(131072, 131072, 131072) -- move it farther away from the center of the ga- i mean experience
--remove arms (stickbug and possibly other ugc avatars have long arms and short bodies)
for _, part in armParts do
model["Left"..part]:Destroy()
model["Right"..part]:Destroy()
end
--size time
local useless, size = model:GetBoundingBox()
print(size.Y)
if size.Y < normalYSize then
print("avatar has failed the size check!")
plr:Kick("Avatar size too small! Please make your avatar larger.")
end
end)
end)
All the code for the people who don’t want to go through the tutorial is above. Now, time to actually learn.
Plan it out
Not-so crucial, but sure.
We need to plan what the code will do.
- The code will detect the Y axis size of a player.
- The code will remove the arms of a player to get a more accurate size (arms can be longer than the body sometimes)
- The code will kick the player if the avatar is too small. However, you can make it do whatever you want to.
Setting up the script
Setup a script! Simple, right?
Make a script (not to get confused with localscript) and put it in Workspace or ServerScriptService.
Name it anything! I’ll name mine “AntiSmallAvatarScript”.
Thats it!
Variables
You really need two, but whatever.
Open up the script first. Then, remove the print("Hello, World!")
. The script should be blank.
Now, let’s add the variables.
normalYSize
The size threshold.
This is the Y axis size threshold that when exceeded, the script will do it’s thing.
local normalYSize = 4.65 --this is a bit lower than the height of a normal avatar with all size settings cranked down
armParts
You wont understand now but it’s for later.
Just copy this down for now, you’ll understand later.
local armParts = {
"UpperArm",
"LowerArm",
"Hand"
}
That’s all for variables!
Code time!
Yeah!
Foundation
Everything has a foundation!
Start off with a PlayerAdded event, and a CharacterAdded event inside that event.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
--this is where all the code is going!
end)
end)
If you’re asking why I don’t get the character parameter, it’s because we don’t really need it.
Next, we are going to get a model of the character by using CreateHumanoidModelFromUserId for the size comparison.
Let’s make sure this is R15, since UGC avatar only supports R15.
if model:WaitForChild("Humanoid").RigType == Enum.HumanoidRigType.R6 then model:Destroy() return end
Next, we are going to get a model of the character by using CreateHumanoidModelFromUserId for the size comparison.
local model = game.Players:CreateHumanoidModelFromUserId(plr.UserId)
Lastly, let’s parent it to workspace and move it far from the center of the game.
model.Parent = workspace
model.PrimaryPart.CFrame = CFrame.new(131072, 131072, 131072)
Now, time for the challenge that may seem hard for some people but is pretty simple.
Size
Hard part, unless…
We can achieve this by using a function called GetBoundingBox. This function returns the orientation and size of the model.
So, let us utilize it, shall we?
local useless, size = model:GetBoundingBox()
This script doesn’t necessarily focus on how skinny an avatar is, just how short it is, so all we need is the Y axis of the model.
Comparison
Easy as pie!
Just a quick if statement, do whatever you want if it is true, but I will kick the player.
if size.Y < normalYSize then
print("avatar has failed the size check!")
plr:Kick("Avatar size too small! Please make your avatar larger.")
end
And we are do-
wait…
Somethings wrong.
I thought this tutorial worked!
This is the outputted player size.
The avatar used was apparently ~3.5 studs tall without animations.
This got me a bit stuck.
I was struggling there, analyzing the avatar.
But something saves me from being stuck on this problem.
It’s the…
Object hightlight?
Might sound funny, but it’s true.
I accidentally put my mouse on it, and something comes up.
The arms are longer than they appear!
This is quite the simple fix. Before the check, we remove the arms (and accessories that might increase height) to get the true size. This was the purpose of the armParts variable we made.
Simple fix.
for _, part in armParts do
model["Left"..part]:Destroy()
model["Right"..part]:Destroy()
end
for _, part in model:GetChildren() do
if part:IsA("Accessory") then
part:Destroy()
end
end
--if statement here!!! make sure to put the code before the if statement!!!
Now, will this actually work?
Only one way to find out.
Test time!!!
You better impress me.
I bought this smallest avatar set I found on youtube that costed 150 robux and put it on.
The result…
It works!
Thank’s for reading this tutorial! I hope you learned or found something you need!