Trying to scale character with a GUI, attempt to index nil with WaitForChild

local button = script.Parent 
local player = game.Players.LocalPlayer
button.MouseButton1Down:Connect(function()
	if player then
		local humanoid = player:FindFirstChild("Humanoid")
		local height = humanoid:WaitForChild("BodyHeightScale").Value
		if humanoid then
			if humanoid:FindFirstChild("BodyHeightScale") then
			humanoid.BodyHeightScale.Value = height - 0.05
			end
		end
	end
end)

Title says it all. I’m having trouble with trying to scale my characters with textbuttons, and I keep getting the output error
“[Players.TritoNotTrito.PlayerGui.ScreenGui.TextButton.LocalScript:6: attempt to index nil with ‘WaitForChild’]”. I’ve tried several things, like using a local instead of the value (but that didn’t work and would cause problems with the other text button, which is supposed to make you taller). Help would be appreciated!

You’re trying to get the Humanoid of a player object. Use player.Character.Humanoid instead.

local player = game.Players.LocalPlayer

Clicked:Connect bla bla
  local character = player.Character or player.CharacterAdded:Wait()
  local humanoid = character:WaitForChild("Humanoid)
end)
1 Like

Thank you so much! Can’t believe it was such a simple mistake, thank you for solving my issue.