I have a script that should play a particular animation when the player moves, based on a local value that is sent via remote event to a server animation script. The animations play, however, the alternate animation only plays when the D key is pressed, rather then when W,A,S AND D are pressed. Any help is appreciated.
-----The Local Script----
local player = game:GetService("Players").LocalPlayer
local MovementStyle
local IdleStyle
local MovementAsset = {"rbxassetid://643347794","rbxassetid://643348089"}
local Mouse = player:GetMouse()
local Target = Mouse.Target
local MotionEvent = game.ReplicatedStorage:WaitForChild("MotionEvent")
local InteractEvent = game.ReplicatedStorage:WaitForChild("Interact")
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.D
and script.CharacterState.Value == "Exploration" then
MovementStyle = ("rbxassetid://661645004")
IdleStyle = ("rbxassetid://661054611")
MotionEvent:FireServer(MovementStyle,IdleStyle)
print(MovementStyle)
elseif script.CharacterState.Value == "Combative"
and inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.D then
MovementStyle = ("rbxassetid://658801474")
IdleStyle = ("rbxassetid://658368358")
MotionEvent:FireServer(MovementStyle,IdleStyle)
print(MovementStyle)
elseif inputObject.KeyCode == Enum.KeyCode.F and script.CharacterState.Value == "Exploration" then
script.CharacterState.Value = "Combative"
elseif inputObject.KeyCode == Enum.KeyCode.F and script.CharacterState.Value == "Combative" then
script.CharacterState.Value = "Exploration"
--InteractEvent:FireServer(Target.Parent,Target.Parent.Name)
-- elseif inputObject.KeyCode == Enum.KeyCode.LeftShift then
--print("Sprinting Toggled!")
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
---------------------The Server script---------------------
local Pawn = script.Parent
local already_ran = false
local grounded = false
local Anim = Instance.new("Animation")
local event = game.ReplicatedStorage:WaitForChild("MotionEvent")
-----ANIMATION VALUES---
function playAnimation(parent)
local AnimTrack = Pawn.Humanoid:LoadAnimation(Anim)
AnimTrack:Stop()
wait(.01)
AnimTrack:Play()
AnimTrack:AdjustSpeed(1)
end
event.OnServerEvent:connect(function(player,MovementStyle,IdleStyle) -- OnServerEvent automatically passes the player who fired it as the first argument.
local Movement = MovementStyle
local Idle = IdleStyle
--print(Movement)
local function onGround(speed)
if grounded == false then
grounded = true
end
if speed < 1 then
for _,anim in pairs(Pawn.Humanoid:GetPlayingAnimationTracks()) do
anim:Stop()
break
end
already_ran = false
Anim.AnimationId = (Idle)
playAnimation(Anim)
elseif speed > 0 then
if already_ran == false then
already_ran = true
for _,anim in pairs(Pawn.Humanoid:GetPlayingAnimationTracks()) do
anim:Stop()
break
end
--print(Movement)
Anim.AnimationId = (Movement)
playAnimation(Anim)
end
end
end
Pawn.Humanoid.Running:connect(onGround)
end)

1 comment
Are They The Correct Animation ID's