Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Bugged but I don't know why?

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

0

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)

0

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.

0

im assuming its the input service end, also its strange that u didnt get an error after line 16 "USI"

0

what is USI

0

I assume he made USI the variable for the UserInputService service.

0

Yeah, it's UserInputSerive, I just found USI saves lots of space, also I fixed the script.

1 answer

Figured it out:

USI.InputBegan:connect(function(inputObject)
	if player.Character then
		if inputObject.KeyCode == Enum.KeyCode.A then
			turnSpeed = turnSpeed + 7.5
		end
		if inputObject.KeyCode == Enum.KeyCode.D then
			turnSpeed = turnSpeed - 7.5
		end
	end
end)

USI.InputEnded:connect(function(inputObject)
	if player.Character then
		if inputObject.KeyCode == Enum.KeyCode.A then
			turnSpeed = turnSpeed - 7.5
		end
		if inputObject.KeyCode == Enum.KeyCode.D then
			turnSpeed = turnSpeed + 7.5
		end
	end
end)
while character do
	root.CFrame = root.CFrame*CFrame.Angles(math.rad(0), math.rad(turnSpeed), math.rad(0))
	wait()
end

I figured out that problem was that multipul anlges were being set but not all at the same time, causing the character to wiggle. So I made it where only one angle was changed for the whole script rather than the whole time.

This discussion is preserved as it was. New answers, comments, and votes are closed.