Hello! Im trying to make a scale script for all of the players that play my game.
The Issue Is I want it to make me small ( 0.5 ) but It wont work at all and I don’t know what Im doing wrong also I want it to do it with all of the parts with the players avatar, I tried another script but It didn’t work. I also wanna make it so when you die your the same size.
function PlayerSize(player)
local SizeValue = 0.5
local humanoid = player.Character.Humanoid
if humanoid then
if humanoid:FindFirstChild("BodyHeightScale")then
humanoid.BodyHeightScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyWidthtScale")then
humanoid.BodyWidthScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyDepthScale")then
humanoid.BodyDepthScale.Value = SizeValue
end
if humanoid:FindFirstChild("HeadScale")then
humanoid.HeadScale.Value = SizeValue
end
end
end
wait(1)
for i, player in pairs(game.Players:GetPlayers()) do
PlayerSize(player)
end
Need a little more information than “it won’t work”. The code looks fine. What does your output window say? Nothing? Errors? Where is the script sitting? Workspace? ReplicatedStorage? ServerScriptService? Is it a local script or a server script?
function PlayerSize(player)
local SizeValue = 0.5
local char=player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")
if humanoid then
if humanoid:FindFirstChild("BodyHeightScale")then
humanoid.BodyHeightScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyWidthtScale")then
humanoid.BodyWidthScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyDepthScale")then
humanoid.BodyDepthScale.Value = SizeValue
end
if humanoid:FindFirstChild("HeadScale")then
humanoid.HeadScale.Value = SizeValue
end
end
end
wait(1)
for i, player in pairs(game.Players:GetPlayers()) do
PlayerSize(player)
end
The only thing I added to your existing code was this line:
local char=player.Character or player.CharacterAdded:wait()
The loop at the end is probably not the best approach to solving this problem. Alternatively, you can do something like this :
local Players = game:GetService:Players()
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
PlayerSize(char)
end)
end)
In this case, you’ll need to modify the PlayerSize function to take a character as the argument instead of a player, like so:
function PlayerSize(char)
local SizeValue = 0.5
local humanoid = char:FindFirstChild("Humanoid")
if humanoid then
if humanoid:FindFirstChild("BodyHeightScale")then
humanoid.BodyHeightScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyWidthtScale")then
humanoid.BodyWidthScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyDepthScale")then
humanoid.BodyDepthScale.Value = SizeValue
end
if humanoid:FindFirstChild("HeadScale")then
humanoid.HeadScale.Value = SizeValue
end
end
end
13:08:28.970 ServerScriptService.Script:4: attempt to index nil with 'Humanoid' - Server - Script:4
13:08:28.970 Stack Begin - Studio
13:08:28.970 Script 'ServerScriptService.Script', Line 4 - function PlayerSize - Studio - Script:4
13:08:28.970 Script 'ServerScriptService.Script', Line 23 - Studio - Script:23
13:08:28.971 Stack End - Studio
This error happens because the character has not loaded when the function is called, so using the “.” operator will result in an error because the player’s character does not presently exist. See my earlier post and try that approach, or use:
local char = plr.Character or plr.CharacterAdded:Wait()
You will have to give it time for your character’s content to load. You are getting that weird body effect because your bodyheight, bodydepth, and headscales load in before your bodywidth. Instead of :FindFirstChild(), try using :WaitForChild()
This also applies to local humanoid = char:FindFirstChild("Humanoid")
function Size(Player)
local Char = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Char:WaitForChild("Humanoid")
local BodyHeightScale = Humanoid:WaitForChild("BodyHeightScale")
local BodyDepthScale = Humanoid:WaitForChild("BodyDepthScale")
local BodyWidthScale = Humanoid:WaitForChild("BodyWidthScale")
local HeadScale = Humanoid:WaitForChild("HeadScale")
BodyHeightScale.Value = 0.525
BodyDepthScale.Value = 0.5
BodyWidthScale.Value = 0.5
HeadScale.Value = 0.5
end
function PlayerSize(player)
local SizeValue = 0.5
local char=player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")
if humanoid then
if humanoid:FindFirstChild("BodyHeightScale")then
humanoid.BodyHeightScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyWidthtScale")then
humanoid.BodyWidthScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyDepthScale")then
humanoid.BodyDepthScale.Value = SizeValue
end
if humanoid:FindFirstChild("HeadScale")then
humanoid.HeadScale.Value = SizeValue
end
end
end
wait(1)
for i, player in pairs(game.Players:GetPlayers()) do
PlayerSize(player)
end
local function PlayerSize(char)
local SizeValue = 0.5
local humanoid = char:WaitForChild("Humanoid")
if humanoid then
if humanoid:FindFirstChild("BodyHeightScale") then
humanoid.BodyHeightScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyWidthtScale") then
humanoid.BodyWidthScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyDepthScale") then
humanoid.BodyDepthScale.Value = SizeValue
end
if humanoid:FindFirstChild("HeadScale") then
humanoid.HeadScale.Value = SizeValue
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
PlayerSize(char)
end)
end)
The issue is that you tried to get the character AND the humanoid straight away, while none of those have loaded yet. You can use the PlayerAdded event to get when a player joins, and the CharacterAdded event of the player to get whenever the player loads (including when a player dies)