Problem With Tank Control's

Sup devforum! I know the whole audio update shenanagins have been pretty bad but I kinda need help with something. I’ve been looking around and came across a tank control script and modified it a bit. However there is a glaring issue. Whenever you try and move back, this happens:

Here’s some of the code:

local script:

local function OnBackward (actionName, inputState)
    if inputState == Enum.UserInputState.Begin then
        movingback = true
        moving = false
        while movingback do
        rotation = player.Character.HumanoidRootPart.Orientation.Y
        Xdirection = math.sin(0.0174532925*rotation)*-1*-1
        Zdirection = math.cos(0.0174532925*rotation)*-1*-1
        wait()
        end
    elseif inputState == Enum.UserInputState.End then
        movingback = false
        Xdirection = 0
        Zdirection = 0
    end
end
ContextActionService:BindAction("Backward", OnBackward, true, Enum.KeyCode.S)

Server script:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local hum = char:WaitForChild("Humanoid")
        hum.AutoRotate = false
    end)
end)
3 Likes

Realized I left out some variables

local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")


local leftValue, rightValue, forwardValue, backwardValue = 0, 0, 0, 0

local Xdirection, Zdirection, rotation = 0, 0, 0

local moving = false
local movingback = false
local function OnUpdate()
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		player.Character.HumanoidRootPart.CFrame *= CFrame.Angles(0, math.rad( (leftValue - rightValue) * 2 ), 0)
		player.Character.Humanoid:Move( Vector3.new(Xdirection, 0, Zdirection), false )
	end
end

Adding on to this, I accidentally forgot

RunService:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, OnUpdate)

That’s a weird script not sure about the math used.

I prefer this other method:

I tried adapting this with my code already just for the back since the front, and the sides isn’t exactly what I was planning but uh… this happens:

1 Like

Solved, by moving a part of my script out of the local script it fixed itself.

1 Like