2d Control Not Functioning Property (read description carefully)

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

1 Like

Invis part allignposition to player HRP/head, camera offset to this new target

now no matter what happens the camera is fixed to a different subject so nothing buggy can happen.

my bad i was previously having an issue with my camera but i was able to fix it

also sorry for late reply as well

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.