Attemt to index nil with "PrimaryPart"

Hello, i’m tried to create script that disables the bouncing when falling from high distance.
But i’m found bug that i’m can’t fix

local char = script.Parent

local hum = char:WaitForChild("Humanoid")

local function removeVelocity(character)

local vectorZero = Vector3.new(0, 0, 0)

character.PrimaryPart.Velocity = vectorZero

character.PrimaryPart.RotVelocity = vectorZero

end

hum.StateChanged:Connect(function(oldState, newState)

if newState == Enum.HumanoidStateType.Freefall then

removeVelocity()

end

end)

I’m tried to fix it with :FindFirstChild. But this won’t work.

The thing is you are not passing character.

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

local function removeVelocity(character)
	local vectorZero = Vector3.new(0, 0, 0)
	character.PrimaryPart.Velocity = vectorZero
	character.PrimaryPart.RotVelocity = vectorZero
end

hum.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Freefall then
		removeVelocity(char)
	end
end)

Step 2

Or since you are already storing character, then replace character with char
image

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

local function removeVelocity()
	local vectorZero = Vector3.new(0, 0, 0)
	char.PrimaryPart.Velocity = vectorZero
	char.PrimaryPart.RotVelocity = vectorZero
end

hum.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Freefall then
		removeVelocity()
	end
end)

You need to pass in char when you’re calling the function removeVelocity

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

local function removeVelocity(character)
   local vectorZero = Vector3.new(0, 0, 0)
   character.PrimaryPart.Velocity = vectorZero
   character.PrimaryPart.RotVelocity = vectorZero
end

hum.StateChanged:Connect(function(oldState, newState)
  if newState == Enum.HumanoidStateType.Freefall then
   removeVelocity(char) --you need to provide the character, since you provided `character` as the pram in your function.
  end
end)

The reason you got that error is because your function doesn’t know what character is. When you provide params into a function, you need to provide matching arguments when calling it.

I’m know that im have char. But i’m I tried to replace it with char. There was the same error.
But i’m can try removeVelocity(char)