So I am making a game where you control a ball by moving the world around it like Super Monkey Ball however when I spam all of the keys this slight rotation is occurring and its making me mad.
I tried adding it so two tweens can’t go at once but that still didn’t fix it I am confused on why and how this is happening at all.
For more context this is taking place inside of a local script.
local CAS = game:GetService("ContextActionService")
local TS = game:GetService("TweenService")
local base = workspace:WaitForChild("Base")
local StartCFrame = base.CFrame
local Orientation = base.CFrame
local turn = 10
local Active = false
local function Control(actionName, inputState, inputObject)
local num
if inputState == Enum.UserInputState.Begin then
num = 1
elseif inputState == Enum.UserInputState.End then
num = -1
else
return
end
if actionName == "Left" then
Orientation = Orientation*CFrame.Angles(math.rad(turn*num),0,0)
elseif actionName == "Right" then
Orientation = Orientation*CFrame.Angles(math.rad(-turn*num),0,0)
elseif actionName == "Up" then
Orientation = Orientation*CFrame.Angles(0,0,math.rad(turn*num))
elseif actionName == "Down" then
Orientation = Orientation*CFrame.Angles(0,0,math.rad(-turn*num))
end
if Active then wait() end
local tween = TS:Create(base, TweenInfo.new(0.2), {CFrame = Orientation})
Active = true
tween:Play()
tween.Completed:Wait()
Active = false
end
CAS:BindAction("Left", Control, false, Enum.KeyCode.A)
CAS:BindAction("Right", Control, false, Enum.KeyCode.D)
CAS:BindAction("Up", Control, false, Enum.KeyCode.W)
CAS:BindAction("Down", Control, false, Enum.KeyCode.S)
