Hey. I made a sword tool animations, in different states, it will play a different animation.
I used :GetState()
to detect and landing, but it doesn’t work.
Here is my code:
wait(1)
local tool = script.Parent.Parent;
local userInputService = game:GetService("UserInputService");
local tweenService = game:GetService("TweenService");
local localPlayer = game:GetService("Players").LocalPlayer;
local humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid");
local remoteEvent = script.Parent:WaitForChild("Remote");
local isRunning = false;
local currentAnimation = nil;
local isEquipped = false;
local animations = {
Idle = game:GetService("ReplicatedStorage").SwordAnimations.Idle;
Walking = game:GetService("ReplicatedStorage").SwordAnimations.Walking;
Running = game:GetService("ReplicatedStorage").SwordAnimations.Running;
Jumping = game:GetService("ReplicatedStorage").SwordAnimations.Jumping;
Fall = game:GetService("ReplicatedStorage").SwordAnimations.Fall;
};
local c = coroutine.wrap(function()
while wait() do
if not isEquipped then remoteEvent:FireServer("Stop", nil) coroutine.yield() end
if localPlayer.IsDashing.Value then
currentAnimation = "Dashing"
end
if humanoid.MoveDirection == Vector3.new() and not localPlayer.IsDashing.Value then
--Idle
if currentAnimation ~= animations.Idle and not humanoid:GetState() == Enum.HumanoidStateType.Jumping and not localPlayer.IsDashing.Value then
remoteEvent:FireServer("Play", animations.Idle)
currentAnimation = animations.Idle
end
elseif humanoid.MoveDirection ~= Vector3.new() and not isRunning and not humanoid:GetState() == Enum.HumanoidStateType.Jumping and not localPlayer.IsDashing.Value then
--Walking
if currentAnimation ~= animations.Walking then
remoteEvent:FireServer("Play", animations.Walking)
currentAnimation = animations.Walking
end
elseif humanoid.MoveDirection ~= Vector3.new() and isRunning and not humanoid:GetState() == Enum.HumanoidStateType.Jumping and not localPlayer.IsDashing.Value then
--Running
if currentAnimation ~= animations.Running and not localPlayer.IsDashing.Value and not humanoid:GetState() == Enum.HumanoidStateType.Jumping then
remoteEvent:FireServer("Play", animations.Running)
currentAnimation = animations.Running
end
elseif humanoid:GetState() == Enum.HumanoidStateType.Jumping then
print("Jumping")
--Jumping
if currentAnimation ~= animations.Jumping and not localPlayer.IsDashing.Value then
remoteEvent:FireServer("Play", animations.Jumping)
currentAnimation = animations.Jumping
end
elseif humanoid:GetState() == Enum.HumanoidStateType.Landed then
if currentAnimation ~= animations.Fall and not localPlayer.IsDashing.Value then
humanoid:LoadAnimation(animations.Fall):Play()
currentAnimation = animations.Fall
end
end
end
end)
function on_Equip()
isEquipped = true
c()
localPlayer.CameraMovementRelative.Value = false
end
function on_Unequip()
isEquipped = false
tweenService:Create(workspace.CurrentCamera, TweenInfo.new(.3), {FieldOfView = 70}):Play()
currentAnimation = nil;
localPlayer.CameraMovementRelative.Value = true
end;
function input_Began(input, gpe)
if gpe then return end;
if not isEquipped then return end;
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = true
tweenService:Create(workspace.CurrentCamera, TweenInfo.new(.3), {FieldOfView = 90}):Play()
end
end;
function input_Ended(input, gpe)
if gpe then return end;
if not isEquipped then return end;
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
tweenService:Create(workspace.CurrentCamera, TweenInfo.new(.3), {FieldOfView = 70}):Play()
end
end;
-- // Connecting the events
tool.Equipped:Connect(on_Equip);
tool.Unequipped:Connect(on_Unequip);
userInputService.InputBegan:Connect(input_Began);
userInputService.InputEnded:Connect(input_Ended)
(Note: Before I used :GetState() it worked PERFECTLY fine)
This is a LocalScript