Okay so I'm making a "2d" game in ROBLOX where its just the player moving on the X and Y plane and never moving on the Z plane. So I scripted a moving camera to follow the player through the level and a custom walking system okay. HOWEVER! When you hold "A" or "D" for 13 seconds ("A" and "D" are my only walk keys, "A" for left and "D" for right) it just randomly stops you in your trakcs! You just quit moving! All the sudden you're running and singing lalalalalalala then BOOM, YOU STOP MOVING. I counted the intervals between the stops man! It's always 13 seconds then it stops! Doesn't matter where you're walking but when it reaches 13 seconds it just quits. I don't know if UserInputService only supports a keypress of 13 seconds or if the Humanoid.WalkToPoint can only last for 13 seconds but I feel there is a conspiracy against me. Everytime I close my eyes I see like that part from Black Ops 1 with the numbers but it's just 13. It's just flashing red 13 man! I can't deal with this anymore. Does anyone have a solution or an explanation to this madness. Here is my code, it is a localscript(yea i didnt use any remotes yet but whatever) in the startergui. Also you'll notice how I get my player to walk is by placing 2 parts in workspace at the ends of the map and use the WalkToPoint property of Humanoid to make it walk to left and right, then to get it to stop moving when the key is released is by having MoveToPoint be the HumanoidRootPart.

local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
local CurrentCam = game.Workspace.CurrentCamera
local Cam = game.Workspace:WaitForChild("Cam")





CurrentCam.CameraSubject = Humanoid
CurrentCam.CameraType = Enum.CameraType.Scriptable
CurrentCam.CoordinateFrame = CFrame.new(Cam.Position) * CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))





Humanoid.Running:connect(function(Speed)
while Speed > 0 do
CurrentCam.CoordinateFrame = CFrame.new(Character.HumanoidRootPart.Position.X, Character.HumanoidRootPart.Position.Y, Cam.Position.Z) * CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))
wait()
end
end)

while Humanoid.Jumping == true or Humanoid.FloorMaterial == Enum.Material.Air do
CurrentCam.CoordinateFrame = CFrame.new(Character.HumanoidRootPart.Position.X, Character.HumanoidRootPart.Position.Y, Cam.Position.Z) * CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))
wait()
end





function LeftKeyPressed(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.A then
Humanoid.WalkToPoint = Vector3.new(game.Workspace.Left.Position.X, game.Workspace.Left.Position.Y, game.Workspace.Left.Position.Z)
end
end

function LeftKeyReleased(inputObject,gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.A then
Humanoid.WalkToPoint = Vector3.new(Character.HumanoidRootPart.Position.X, Character.HumanoidRootPart.Position.Y, Character.HumanoidRootPart.Position.Z)
end
end

function RightKeyPressed(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.D then
Humanoid.WalkToPoint = Vector3.new(game.Workspace.Right.Position.X, game.Workspace.Right.Position.Y, game.Workspace.Right.Position.Z)
end
end

function RightKeyReleased(inputObject,gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.D then
Humanoid.WalkToPoint = Vector3.new(Character.HumanoidRootPart.Position.X, Character.HumanoidRootPart.Position.Y, Character.HumanoidRootPart.Position.Z)
end
end

function JumpKeyPressed(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.W then
Humanoid.Jump = true
end
end

function JumpKeyReleased(inputObject,gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.W then
end
end

game:GetService("UserInputService").InputBegan:connect(LeftKeyPressed)
game:GetService("UserInputService").InputEnded:connect(LeftKeyReleased)
game:GetService("UserInputService").InputBegan:connect(RightKeyPressed)
game:GetService("UserInputService").InputEnded:connect(RightKeyReleased)
game:GetService("UserInputService").InputBegan:connect(JumpKeyPressed)
game:GetService("UserInputService").InputEnded:connect(JumpKeyReleased)

6 comments

0

Maybe my keyboard only supports a 13 second keydown even tho i doubt corsair would skimp on me like that.

0

Actually scratch that because default moving doesnt do that for me, it must be the code! SOMEWHERE IT IS IN THERE!

2

Dude I don't know that much about user input service yet but I do have some really really important advice. Always indent your code. Period. It makes the code look organized, easier to read, and helps you spot problems before they happen. It also to some extent shows that you know what you are doing.

0

All I can really share is that with my pathfinding I have been working on, if the NPC encounters an obstacle between it and the destination, it will either move to the next node or stop without going to the node when I use MoveToFinished:Wait(). Just wanted to share that.

0

@Phlegethon5778 I am an avid AntiIndenter. I have no problems reading my code and I'd rather not look at a disgusting pinetree of ends when I do something that requires alot of if statements.