ok 1 more question, how would i efficiently switch animation because when i change it freezes until i stop and walk again
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")
local WalkAnim = Animate:WaitForChild("walk"):WaitForChild("WalkAnim")
local RunAnim = Animate:WaitForChild("run"):WaitForChild("RunAnim")
local IdleAnim1 = Animate:WaitForChild("idle"):WaitForChild("Animation1")
local IdleAnim2 = Animate:WaitForChild("idle"):WaitForChild("Animation1")
local AnimationList = {
WalkAnimationId = "[blocked by filter]",
SprintAnimationId = "[blocked by filter]",
}
local function ReplaceAnimation(OldAnim, newAnimId, AnimationName)
OldAnim.AnimationId = newAnimId
-- print('Changing '.. OldAnim.Name .. ' to ' .. AnimationName)
wait(0.1)
for _,oldPlayingAnimation in pairs(Humanoid:GetPlayingAnimationTracks()) do
print(oldPlayingAnimation.Name)
oldPlayingAnimation:Stop()
end
end
game:GetService("RunService").RenderStepped:connect(function()
if Character:FindFirstChild("ShiftSpeedBoost") then --if Sprinting
if RunAnim.AnimationId ~= AnimationList.SprintAnimationId then
ReplaceAnimation(RunAnim, AnimationList.SprintAnimationId, "Sprint")
ReplaceAnimation(WalkAnim, AnimationList.SprintAnimationId, "Sprint")
end
else --If not sprinting
if tostring(RunAnim.AnimationId) ~= tostring(AnimationList.WalkAnimationId) then
ReplaceAnimation(RunAnim, AnimationList.WalkAnimationId, "DefaultWalk")
ReplaceAnimation(WalkAnim, AnimationList.WalkAnimationId, "DefaultWalk")
end
end
end)
game:GetService("UserInputService").InputEnded:connect(function(inputObject, gameProcessedEvent)
if gameProcessedEvent == true then return end
if inputObject.UserInputType == Enum.UserInputType.Keyboard then
if inputObject.KeyCode == Enum.KeyCode.One then
if Character:FindFirstChild("ShiftSpeedBoost") then
Character:FindFirstChild("ShiftSpeedBoost"):Destroy()
else
local newObj = Instance.new("ObjectValue", Character)
newObj.Name = "ShiftSpeedBoost"
end
end
end
end)
|