Character shrinker script not working as intended

Hey developers!

Could anyone aid me as to why this simple script does not work. It should work accordingly but does not…:confused:

Basically, in this script when a player touches a part they decrease in size.

Below is the image of the output and the script. The output keeps saying that BodyScale as well as all the other members of the humanoid are not valid… Why?

If anyone could help that would be appreciated.
Thanks,
Nick:)

1 Like

Believe it should be HeadScale

2 Likes

OOPS. Nvm that was simple.
Thank you:)

The error suggests that BodyScale does not exist within the Humanoid. Try this instead:

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    
    if player then
        for _, child in pairs(player.Character.Humanoid:GetChildren()) do
            if child:IsA("NumberValue") then
                child.Value = 0.5
            end
        end
    end
end)

Also do make sure to mark the post that helped you the most as a solution, so that members are aware about it rather than just renaming the topic :wink:

1 Like

Thank you!

I had one more question how do I play a sound within that script, above?

You could reference a debounce (Or a cooldown) so that the Sound can play in its entirely before setting it back to false

local Button = script.Parent
local Sound = Button.SoundToPlay
local DB = false

Button.Touched:Connect(function(Hit)
    local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")

    if Humanoid and not DB then
        --Set your Humanoid Scales here
        DB = true
        Sound:Play()

        Sound.Ended:Wait()
        DB = false
    end
end)
local Sound = game.Workspace.Teleport

local button = script.Parent

button.Touched:Connect(function(hit)

local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')

if humanoid then

Sound:Play()

humanoid.HeadScale.Value = 0.5

humanoid.BodyWidthScale.Value = 0.5

humanoid.BodyHeightScale.Value = 0.5

humanoid.BodyDepthScale.Value = 0.5

end

end)

I did that but the sound doesn’t work…

You didn’t reference a debounce in the script, so the sound would result in it playing over & over again

local Button = script.Parent
local Sound = workspace.Teleport
local DB = false

Button.Touched:Connect(function(Hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")

    if humanoid and not DB then
        humanoid.HeadScale.Value = 0.5
        humanoid.BodyWidthScale.Value = 0.5
        humanoid.BodyHeightScale.Value = 0.5
        humanoid.BodyDepthScale.Value = 0.5
        DB = true
        Sound:Play()

        Sound.Ended:Wait()
        DB = false
    end
end)

Either that or it’s something else having to do with your Sound object

1 Like

Play is not a valid member of Part “Workspace.Teleport”

If both of your Objects are named “Teleport”, change the Sound to “TeleportSound” so that they’re both different names oof

Oh it worked. Thanks! Much appreciated. <3