I’m trying to make a script that anchors the player when he’s not moving, but when the player jumps the script ends up anchoring the player in the air …
To close this post I need to correct this.
local function checkMovement(): boolean
for i, keys in pairs(keysPressed) do
if keys == true then
return true
else end
end
return false
end
local function anchorHumanoidRootPart()
while true do
task.wait()
local moving = checkMovement()
if moving == true then
hrp.Anchored = false
else
task.wait(0.1)
if isJumping == false then
hrp.Anchored = true
end
end
end
end
uis.InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.D or inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.Space then
print(inputObject.KeyCode)
print(inputObject.KeyCode.Value)
keysPressed[tostring(inputObject.KeyCode)] = true
end
end
uis.InputEnded:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.D or inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.Space then
keysPressed[tostring(inputObject.KeyCode)] = false
end
end
humanoid.Jumping:Connect(function(isActive)
if isActive then
isJumping = true
print(isJumping)
else
isJumping = false
print(isJumping)
end
end)