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.
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
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)
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.