Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Bugged but I don't know why?

Asked by 5 years ago
Edited 5 years ago

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?

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) awfulszn 394 — 5y
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. paperbagstudio 28 — 5y
0
im assuming its the input service end, also its strange that u didnt get an error after line 16 "USI" greatneil80 2647 — 5y
0
what is USI greatneil80 2647 — 5y
View all comments (2 more)
0
I assume he made USI the variable for the UserInputService service. awfulszn 394 — 5y
0
Yeah, it's UserInputSerive, I just found USI saves lots of space, also I fixed the script. paperbagstudio 28 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question