Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script that shrinks players avatar upon joining can't find humanoid?

Asked by 2 years ago

So I made a simple script that is meant to shrink a players avatar once they join the game, but when I run it I get an error telling me it can't find the players humanoid, I've tried finding the humanoid with 4 different methods and the script can find the players username easily, if anyone could point out what I've done wrong I would greatly appreciate it!

function PlayerSize(player)
    local SizeValue = 0.6
    local Character = player.Character 

    print(player)

    local humanoid = Character.Humanoid
    if humanoid then 
        print("humanoid found")

        if humanoid:FindFirstChild("BodyHeightScale") then
            humanoid.BodyHeightScale.Value = SizeValue
        end
        if humanoid:FindFirstChild("BodyWidthScale") 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(2)
for i, player in pairs(game.Players:GetPlayers()) do
    PlayerSize(player)
end


0
I think you havnt found the declared the player the script Black_Magic2533 104 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
local player
game.Players.PlayerAdded:Connect(function(Plr)
    player = Plr
end)
function PlayerSize(SizeValue)
    local Character = player.Character 

    print(player)

    local humanoid = Character.Humanoid
    if humanoid then 
        print("humanoid found")

        if humanoid:FindFirstChild("BodyHeightScale") then
            humanoid.BodyHeightScale.Value = SizeValue
        end
        if humanoid:FindFirstChild("BodyWidthScale") 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(2)

PalyerSize(0.6)

I think the player was nil so you can't find the character so try using game.Players.PlayerAdded this function will run if player joins and if you do game.Players.PlayerAdded:Connect(function(Plr)) then this is the Plr is the Player so type local Player or i never try it local Plr so maybe it will asign automaticly but back to loacl Player and in the function you do Player = Plr so the Player is now the variable Player !I just want to mention it's Object so if you want to print player it's better to type Player.Name!

Ad

Answer this question