I have a script that seamlessly moves the character left and right without that rotation for a 2d game I’m trying to make
There is this bug though where when you keep spamming jump you can rotate the camera as long as you’re holding spacebar
I’ve tried to make it detect when the player is jumping to check if it moves left or right like how the script is supposed to work, and it breaks
Here is the script now
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local function faceCharacter(direction)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local targetPosition = humanoidRootPart.Position + (direction == "left" and Vector3.new(-1, 0, 0) or Vector3.new(1, 0, 0))
humanoidRootPart.CFrame = CFrame.lookAt(humanoidRootPart.Position, targetPosition, Vector3.new(0, 1, 0))
end
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.A then
faceCharacter("left")
elseif input.KeyCode == Enum.KeyCode.D then
faceCharacter("right")
end
end
end)
player.CharacterAdded:Connect(function(char)
character = char
end)
I couldn’t record a video since I wasn’t able to replicate the bug