So I'm trying to get it so when the player stops moving, they can regain control of their player and continue actions fluidly, I tried doing repeat wait() until character.Humanoid.Running == false but for obvious reasons, that didn't work
repeat wait() until game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local torso = character.Torso
local walls = game.Workspace.Walls:GetChildren()
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
local lowest = 20
local low
local mag
for _, wall in pairs(walls) do
local distance = (torso.Position - wall.Position).magnitude
mag = distance
if distance < lowest then
lowest = distance
low = wall
end
end
print(low)
if low then
local ray = Ray.new(torso.Position, (low.Position - torso.Position).unit * 999)
local hit, position = game.Workspace:FindPartOnRay(ray, character)
local distance = (position - torso.Position).magnitude
local rayPart = Instance.new("Part", player.Character)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("White")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, torso.Position) * CFrame.new(0, 0, -distance/2)
coroutine.wrap(function()
wait(.5)
rayPart:Destroy()
end)()
--here is where I need help
player.PlayerScripts.ControlScript.Disabled = true
player.Character.Humanoid.WalkToPoint = position
player.Character.Humanoid.WalkSpeed = 23
repeat wait() until character.Humanoid.Running == false
player.Character.Humanoid.WalkSpeed = 16
player.PlayerScripts.ControlScript.Disabled = false
--
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

2 comments
Perhaps check the velocity property of his torso? Something like that.
edited my question