I'm trying to create a simulator, and I want to know how to make my avatar grow slightly as my strength value goes up. Please help!
Edit: The problem seems to be on line 4
while wait(0.5) do local children = game.Players:GetChildren() for i = 1, #children do local humanoid = children[i].Character.Humanoid humanoid.HeadScale.Value = children[i].leaderstats.Strength.Value/50+100 humanoid.BodyHeightScale.Value = children[i].leaderstats.Strength.Value/50+100 humanoid.BodyWidthScale.Value = children[i].leaderstats.Strength.Value/50+100 humanoid.BodyDepthScale.Value = children[i].leaderstats.Strength.Value/50+100 end end
11:49:47.892 - ServerScriptService.Script:4: attempt to index nil with 'Humanoid'
Like marinhren said, there are sizing options in the Humanoid. This is a way to get all players, present and future, and connect them to a function that makes them grow with strength.
local Players = game:GetService("Players") -- Get players local Humanoid function ConnectStrengthToSize(Player) coroutine.wrap(function(Player) Player:WaitForChild("leaderstats"):WaitForChild("Strength").Changed:Connect(function(Value) -- Wait for strength to change Humanoid = Player.Character.Humanoid -- Define humanoid Humanoid.HeadScale.Value = Value/50+100 -- Change size Humanoid.BodyHeightScale.Value = Value/50+100 Humanoid.BodyWidthScale.Value = Value/50+100 Humanoid.BodyDepthScale.Value = Value/50+100 end) end)(Player) -- Run the function end for Index, Player in pairs(Players:GetPlayers()) do ConnectStrengthToSize(Player) -- Connect to size end Players.PlayerAdded:Connect(ConnectStrengthToSize) -- Connect to size
There are certain sizing options inside a R15 Characters's Humanoid. Changing those will change the size of the R15 Character.
e.g. BodyDepthScale.Value, BodyHeightScale.Value, etc..
Do some math to calculate the values of all the sizing.
Hello, you use BodyDepthScale
, BodyHeightScale
, BodyWidthScale
and HeadScale
for it. You also need Script
and not LocalScript.
game.Players.PlayerAdded:Connect(function(player) -- Do the leaderstats here player.CharacterAppearanceLoaded:Connect(function(character) character.Humanoid:WaitForChild("BodyDepthScale").Value = -- Value here character.Humanoid:WaitForChild("BodyHeightScale").Value = -- Value here character.Humanoid:WaitForChild("BodyWidthScale").Value = -- Value here character.Humanoid:WaitForChild("HeadScale").Value = -- Value here end) end)
Also, don't add local children = game.Players:GetPlayers()
and for i = 1, #children do
that isn't needed.