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)```