I’m trying to create a weight for each of my custom characters, and what I mean by weight is the body mass… for example, if one of the characters weighs 70 kg, their footsteps will be heavier than a character who weighs 40 kg, and so on… I also have an ability for one of the characters where they can fly while carrying one of the players, and I want to add the weight logic because flying will be slower and more difficult when carrying a heavy
character.
Also, if one of the characters weighs 50 kg, the sound of their footsteps will be heavier when they carries their hammer because the hammer weighs 20 kg, so the weight of the
character and the weight of their weapon will be added together.
But I don’t know where to start and how to do this… I am a beginner in programming as I started learning only a few months ago.
You might want to put a IntValue in the player using a script.
Make it equal to the weight the player should be.
If they pick up a hammer then add the weight of the hammer to the IntValue.
For flying characters make the script get the IntValue of the weight picked up. If it’s too high then don’t let the flying character pick them up. Make a formula for the speed of the flying character take the value and subtract the percentage of the weight’s value from the speed.
local function FindMassOfModel(Model)
local TotalMass = 0
for i,v in pairs(Model:GetDescendants()) do
if(v:IsA("BasePart")) then
TotalMass += v:GetMass()
end
end
print(Model.Name, "mass = ", math.floor(TotalMass + 0.5)) -- round number down
return TotalMass
end
local function CheckMass(Player)
if Player.Character then
local Mass = FindMassOfModel(Player.Character)
if Mass >= 17 then
warn(Player, "mass too heavy.")
else
print(Player, "mass light enough.")
end
end
end
-- JUST FOR TESTING
local function Test(Child)
if Child:IsA("Model") and game.Players:FindFirstChild(Child.Name) then
print(Child, "spawned into workspace.")
-- initial weight
CheckMass(game.Players:FindFirstChild(Child.Name))
-- adding tool
Child.ChildAdded:Connect(function()
CheckMass(game.Players:FindFirstChild(Child.Name))
end)
-- removed tool
Child.ChildRemoved:Connect(function()
CheckMass(game.Players:FindFirstChild(Child.Name))
end)
end
end
game.Workspace.ChildAdded:Connect(Test)
Just create a Tool in StarterPack then equip/unequip it a few time to see what happens.