So, I know this is the case for Unreal Engine, but Movement Components need to run EVERY TICK to CONSUME the input. In your case, you got an excellent script for detecting player input, but you need to have a tick function that detects ALL inputs and consumes them by adjusting the player’s position/orientation as long as the input is still Begin but never End/Cancelled
I do this for my floating camera script:
--This Table is used to reference all possible consumable inputs from a player
--IE, move forwards, backwards, right left, etc
local InputTable =
{
Forward={Modifier=Vector3.new(0,0,-1),Active=false},
Backwards={Modifier=Vector3.new(0,0,1),Active=false},
Left={Modifier=Vector3.new(-1,0,0),Active=false},
Right={Modifier=Vector3.new(1,0,0),Active=false},
Up={Modifier=Vector3.new(0,1,0),Active=false},
Down={Modifier=Vector3.new(0,-1,0),Active=false}
}
--This function is called every tick to consume the input. It is not responsible for
--resetting the Active values to false because doing so will cause ZERO movement
--All this function does is scan the input table for any Active inputs and add its
--modifier to the current nextMove. Then it returns nextMove
function GetNextMovement(deltaTime)
local nextMove = Vector3.new()
for name,element in pairs(InputTable) do
if element.Active then
nextMove+=element.Modifier
end
end
return CFrame.new(nextMove*(speed*deltaTime))
end
--This function is called whenever the respective key is pressed
local Move=function(actionName,inputState)
if inputState==Enum.UserInputState.Begin then
InputTable[actionName].Active=true
elseif inputState == Enum.UserInputState.End then
InputTable[actionName].Active=false
end
end
--This function is called from the spawn() function. Its a constant tick function that modifies the player's camera based on what GetNextMovement returns
function onSelected()
lastUpdate=tick()
local Root = PhysicalCamera
Camera.CameraSubject=Root
character:WaitForChild("HumanoidRootPart").Anchored=true
while true do
local delta = tick()-lastUpdate
local look = (Camera.Focus.p-Camera.CoordinateFrame.p).unit
local move = GetNextMovement(delta)
local pos = Root.Position
pos=ScrubPosition(pos)
Root.CFrame = CFrame.new(pos,pos+look)*move
lastUpdate=tick()
wait()
end
end
spawn(onSelected)
This code example does not include the action binding at the bottom, and shoudnt since that would be a whole different solution to a different problem.
I hope this code example is a good solution or reference for you!