Walking system goes wrong

Hello developers! So I have a battlegrounds game which I recently added a walking system(different animations than the basic ones offered by Roblox), the system constantly checks in which direction the player is moving, if it moves left, right or back he will walk, else, if it’s moving forward, the player will run. The problem is, for example if I move right, the player will run, and just when I move the second time to right, it will walk; It’s the same problem for moving forward, if I move forward it will walk, and just when I move the second time it will run.

Please tell me if I need to provide more details or you didn’t understand my problem.

Here is the local script:

local UIS = game:GetService("UserInputService")
local RE = game.ReplicatedStorage.Walk
local RE2 = game.ReplicatedStorage.Walk2

local Player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local char = Player.Character or (Player.CharacterAdded:Wait() and Player.Character)
local hum = char:WaitForChild("Humanoid")
	

while true do
	if Player.Character:GetAttribute("isRagdoll") == true then return end
	if Player.Character:GetAttribute("Stunned") then return end
	if Player.Character:GetAttribute("canAttack") == false then return end 
	
	if math.round(hum.MoveDirection:Dot(camera.CFrame.RightVector)) == 1 or math.round(hum.MoveDirection:Dot(camera.CFrame.RightVector)) == -1 or math.round(hum.MoveDirection:Dot(camera.CFrame.LookVector)) == -1 then
	RE2:FireServer()
	end
	
	if math.round(hum.MoveDirection:Dot(camera.CFrame.LookVector)) == 1 then
	RE:FireServer()
	end
	
	wait()
end

Here is the Server Script:

local walkingAniamtionID = "http://www.roblox.com/asset/?id=16768122724"
local walkingAniamtionID2 = "http://www.roblox.com/asset/?id=16768020576"
local animateScript

local players = game.Players
local RE = game.ReplicatedStorage.Walk
local RE2 = game.ReplicatedStorage.Walk2


RE.OnServerEvent:Connect(function(plr)
	animateScript = plr.Character:WaitForChild("Animate")
	animateScript.walk.WalkAnim.AnimationId = walkingAniamtionID
end)

RE2.OnServerEvent:Connect(function(plr)
	animateScript = plr.Character:WaitForChild("Animate")
	animateScript.walk.WalkAnim.AnimationId = walkingAniamtionID2
end)```

i think this will help you

where is this attribute located?

if you looked to image too much, u will see Players object.

game:GetService("Players").UseStrafingAnimations

ok, so I added this attribute but still the same problem. ty though

do not add it as attribute, just enable it.
but if you enabled it and same issue still happening, just disable your animation script for the moment.

I enabled it and still the same problem. But how can disabling the script for a moment make it work?(not really experienced in scripting so thats why I ask this)

this script that you added to StarterPlayer.StarterCharacterScripts

image

find this script at StarterPlayer.StarterCharacterScripts, and disable it
image TO image

…or just disable the main script that changes animation, or just script custom animation

Ok, so after that what should I do?

now test the new animation script, if still not fix your problem, just script custom animation.

So I tested the script that is disabled, but rn nothing works obviously

Rn I have another problem, It is either getting the walk one or the run one.

Here is the script:

local walkingAniamtionID = "http://www.roblox.com/asset/?id=16768122724"
local walkingAniamtionID2 = "http://www.roblox.com/asset/?id=16768020576"
local animateScript

local players = game.Players
local RE = game.ReplicatedStorage.Walk
local RE2 = game.ReplicatedStorage.Walk2


game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
    animateScript = plr.Character:WaitForChild("Animate")
	animateScript.walk.WalkAnim.AnimationId = walkingAniamtionID2
	animateScript.run.RunAnim.AnimationId = walkingAniamtionID
	end)
end)