Ok so I'm making a script where "A" rotates the character counter-clockwise and "D" clockwise, but there is a bug causes the player to wiggle extremely quickly.
local turnSpeed = 7.5
USI.InputBegan:connect(function(inputObject)
if player.Character then
while inputObject.KeyCode == Enum.KeyCode.A do
root.CFrame = root.CFrame*CFrame.Angles(math.rad(0), math.rad(turnSpeed), math.rad(0))
wait()
end
while inputObject.KeyCode == Enum.KeyCode.D do
root.CFrame = root.CFrame*CFrame.Angles(math.rad(0), math.rad(-turnSpeed), math.rad(0))
wait()
end
end
end)
USI.InputEnded:connect(function(inputObject)
if player.Character then
while inputObject.KeyCode == Enum.KeyCode.A do
root.CFrame = root.CFrame*CFrame.Angles(math.rad(0), math.rad(-turnSpeed), math.rad(0))
wait()
end
while inputObject.KeyCode == Enum.KeyCode.D do
root.CFrame = root.CFrame*CFrame.Angles(math.rad(0), math.rad(turnSpeed), math.rad(0))
wait()
end
end
end)
Sometimes the person isn't wiggiling other times he goes really fast, and sometimes he moderitly. How can this be fixed?

6 comments
i'd just set up a value that changes when a player begins and end the input, then run a while loop when its held down and break out of the loop once the value changes (they stop holding)
Well I just made a fix by replacing if/then with while.do but it's glitched a bit. If that can't be fixed I'll try that.
im assuming its the input service end, also its strange that u didnt get an error after line 16 "USI"
what is USI
I assume he made USI the variable for the UserInputService service.
Yeah, it's UserInputSerive, I just found USI saves lots of space, also I fixed the script.