Guest User

roblox error to helping site

a guest
Jun 11th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.78 KB | None | 0 0
  1. I made a humanoid name changing script so now the roblox animate local script dont work anymore, how do i fix this?
  2. i get the error on line 2
  3. i tried to do
  4. ~~~~~~~~~~~~~~~~~
  5. local Humanoid = Character:WaitForChild("Humanoid") or Character:WaitForChild("humanoid name")
  6. ~~~~~~~~~~~~~~~~~
  7. but it didnt work, still got the error message Infinite yield possible on 'Workspace.world_kiIIer:WaitForChild("Humanoid")
  8. ~~~~~~~~~~~~~~~~~
  9. local Character = script.Parent
  10. local Humanoid = Character:WaitForChild("Humanoid")
  11. local pose = "Standing"
  12.  
  13. local userNoUpdateOnLoopSuccess, userNoUpdateOnLoopValue = pcall(function() return UserSettings():IsUserFeatureEnabled("UserNoUpdateOnLoop") end)
  14. local userNoUpdateOnLoop = userNoUpdateOnLoopSuccess and userNoUpdateOnLoopValue
  15. local userAnimationSpeedDampeningSuccess, userAnimationSpeedDampeningValue = pcall(function() return UserSettings():IsUserFeatureEnabled("UserAnimationSpeedDampening") end)
  16. local userAnimationSpeedDampening = userAnimationSpeedDampeningSuccess and userAnimationSpeedDampeningValue
  17.  
  18. local adjustHumanoidRootPartFlagExists, adjustHumanoidRootPartFlagEnabled = pcall(function()
  19.     return UserSettings():IsUserFeatureEnabled("UserAdjustHumanoidRootPartToHipPosition")
  20. end)
  21. local FFlagUserAdjustHumanoidRootPartToHipPosition = adjustHumanoidRootPartFlagExists and adjustHumanoidRootPartFlagEnabled
  22.  
  23. local animateScriptEmoteHookFlagExists, animateScriptEmoteHookFlagEnabled = pcall(function()
  24.     return UserSettings():IsUserFeatureEnabled("UserAnimateScriptEmoteHook")
  25. end)
  26. local FFlagAnimateScriptEmoteHook = animateScriptEmoteHookFlagExists and animateScriptEmoteHookFlagEnabled
  27.  
  28. local AnimationSpeedDampeningObject = script:FindFirstChild("ScaleDampeningPercent")
  29. local HumanoidHipHeight = FFlagUserAdjustHumanoidRootPartToHipPosition and 2 or 1.35
  30.  
  31. local EMOTE_TRANSITION_TIME = 0.1
  32.  
  33. local currentAnim = ""
  34. local currentAnimInstance = nil
  35. local currentAnimTrack = nil
  36. local currentAnimKeyframeHandler = nil
  37. local currentAnimSpeed = 1.0
  38.  
  39. local runAnimTrack = nil
  40. local runAnimKeyframeHandler = nil
  41.  
  42. local animTable = {}
  43. local animNames = {
  44.     idle =  {  
  45.                 { id = "http://www.roblox.com/asset/?id=507766666", weight = 1 },
  46.                 { id = "http://www.roblox.com/asset/?id=507766951", weight = 1 },
  47.                 { id = "http://www.roblox.com/asset/?id=507766388", weight = 9 }
  48.             },
  49.     walk =  {  
  50.                 { id = "http://www.roblox.com/asset/?id=507777826", weight = 10 }
  51.             },
  52.     run =   {
  53.                 { id = "http://www.roblox.com/asset/?id=507767714", weight = 10 }
  54.             },
  55.     swim =  {
  56.                 { id = "http://www.roblox.com/asset/?id=507784897", weight = 10 }
  57.             },
  58.     swimidle =  {
  59.                 { id = "http://www.roblox.com/asset/?id=507785072", weight = 10 }
  60.             },
  61.     jump =  {
  62.                 { id = "http://www.roblox.com/asset/?id=507765000", weight = 10 }
  63.             },
  64.     fall =  {
  65.                 { id = "http://www.roblox.com/asset/?id=507767968", weight = 10 }
  66.             },
  67.     climb = {
  68.                 { id = "http://www.roblox.com/asset/?id=507765644", weight = 10 }
  69.             },
  70.     sit =   {
  71.                 { id = "http://www.roblox.com/asset/?id=2506281703", weight = 10 }
  72.             }, 
  73.     toolnone = {
  74.                 { id = "http://www.roblox.com/asset/?id=507768375", weight = 10 }
  75.             },
  76.     toolslash = {
  77.                 { id = "http://www.roblox.com/asset/?id=522635514", weight = 10 }
  78.             },
  79.     toollunge = {
  80.                 { id = "http://www.roblox.com/asset/?id=522638767", weight = 10 }
  81.             },
  82.     wave = {
  83.                 { id = "http://www.roblox.com/asset/?id=507770239", weight = 10 }
  84.             },
  85.     point = {
  86.                 { id = "http://www.roblox.com/asset/?id=507770453", weight = 10 }
  87.             },
  88.     dance = {
  89.                 { id = "http://www.roblox.com/asset/?id=507771019", weight = 10 },
  90.                 { id = "http://www.roblox.com/asset/?id=507771955", weight = 10 },
  91.                 { id = "http://www.roblox.com/asset/?id=507772104", weight = 10 }
  92.             },
  93.     dance2 = {
  94.                 { id = "http://www.roblox.com/asset/?id=507776043", weight = 10 },
  95.                 { id = "http://www.roblox.com/asset/?id=507776720", weight = 10 },
  96.                 { id = "http://www.roblox.com/asset/?id=507776879", weight = 10 }
  97.             },
  98.     dance3 = {
  99.                 { id = "http://www.roblox.com/asset/?id=507777268", weight = 10 },
  100.                 { id = "http://www.roblox.com/asset/?id=507777451", weight = 10 },
  101.                 { id = "http://www.roblox.com/asset/?id=507777623", weight = 10 }
  102.             },
  103.     laugh = {
  104.                 { id = "http://www.roblox.com/asset/?id=507770818", weight = 10 }
  105.             },
  106.     cheer = {
  107.                 { id = "http://www.roblox.com/asset/?id=507770677", weight = 10 }
  108.             },
  109. }
  110.  
  111. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  112. local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  113.  
  114. local PreloadAnimsUserFlag = false
  115. local PreloadedAnims = {}
  116. local successPreloadAnim, msgPreloadAnim = pcall(function()
  117.     PreloadAnimsUserFlag = UserSettings():IsUserFeatureEnabled("UserPreloadAnimations")
  118. end)
  119. if not successPreloadAnim then
  120.     PreloadAnimsUserFlag = false
  121. end
  122.  
  123. math.randomseed(tick())
  124.  
  125. function findExistingAnimationInSet(set, anim)
  126.     if set == nil or anim == nil then
  127.         return 0
  128.     end
  129.    
  130.     for idx = 1, set.count, 1 do
  131.         if set[idx].anim.AnimationId == anim.AnimationId then
  132.             return idx
  133.         end
  134.     end
  135.    
  136.     return 0
  137. end
  138.  
  139. function configureAnimationSet(name, fileList)
  140.     if (animTable[name] ~= nil) then
  141.         for _, connection in pairs(animTable[name].connections) do
  142.             connection:disconnect()
  143.         end
  144.     end
  145.     animTable[name] = {}
  146.     animTable[name].count = 0
  147.     animTable[name].totalWeight = 0
  148.     animTable[name].connections = {}
  149.  
  150.     local allowCustomAnimations = true
  151.     local AllowDisableCustomAnimsUserFlag = false
  152.  
  153.     local success, msg = pcall(function()
  154.         AllowDisableCustomAnimsUserFlag = UserSettings():IsUserFeatureEnabled("UserAllowDisableCustomAnims2")
  155.     end)
  156.  
  157.     if (AllowDisableCustomAnimsUserFlag) then
  158.         local success, msg = pcall(function() allowCustomAnimations = game:GetService("StarterPlayer").AllowCustomAnimations end)
  159.         if not success then
  160.             allowCustomAnimations = true
  161.         end
  162.     end
  163.  
  164.     -- check for config values
  165.     local config = script:FindFirstChild(name)
  166.     if (allowCustomAnimations and config ~= nil) then
  167.         table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  168.         table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  169.        
  170.         local idx = 0
  171.         for _, childPart in pairs(config:GetChildren()) do
  172.             if (childPart:IsA("Animation")) then
  173.                 local newWeight = 1
  174.                 local weightObject = childPart:FindFirstChild("Weight")
  175.                 if (weightObject ~= nil) then
  176.                     newWeight = weightObject.Value
  177.                 end
  178.                 animTable[name].count = animTable[name].count + 1
  179.                 idx = animTable[name].count
  180.                 animTable[name][idx] = {}
  181.                 animTable[name][idx].anim = childPart
  182.                 animTable[name][idx].weight = newWeight
  183.                 animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  184.                 table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  185.                 table.insert(animTable[name].connections, childPart.ChildAdded:connect(function(property) configureAnimationSet(name, fileList) end))
  186.                 table.insert(animTable[name].connections, childPart.ChildRemoved:connect(function(property) configureAnimationSet(name, fileList) end))
  187.             end
  188.         end
  189.     end
  190.    
  191.     -- fallback to defaults
  192.     if (animTable[name].count <= 0) then
  193.         for idx, anim in pairs(fileList) do
  194.             animTable[name][idx] = {}
  195.             animTable[name][idx].anim = Instance.new("Animation")
  196.             animTable[name][idx].anim.Name = name
  197.             animTable[name][idx].anim.AnimationId = anim.id
  198.             animTable[name][idx].weight = anim.weight
  199.             animTable[name].count = animTable[name].count + 1
  200.             animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  201.         end
  202.     end
  203.    
  204.     -- preload anims
  205.     if PreloadAnimsUserFlag then
  206.         for i, animType in pairs(animTable) do
  207.             for idx = 1, animType.count, 1 do
  208.                 if PreloadedAnims[animType[idx].anim.AnimationId] == nil then
  209.                     Humanoid:LoadAnimation(animType[idx].anim)
  210.                     PreloadedAnims[animType[idx].anim.AnimationId] = true
  211.                 end            
  212.             end
  213.         end
  214.     end
  215. end
  216.  
  217. ------------------------------------------------------------------------------------------------------------
  218.  
  219. function configureAnimationSetOld(name, fileList)
  220.     if (animTable[name] ~= nil) then
  221.         for _, connection in pairs(animTable[name].connections) do
  222.             connection:disconnect()
  223.         end
  224.     end
  225.     animTable[name] = {}
  226.     animTable[name].count = 0
  227.     animTable[name].totalWeight = 0
  228.     animTable[name].connections = {}
  229.  
  230.     local allowCustomAnimations = true
  231.     local AllowDisableCustomAnimsUserFlag = false
  232.  
  233.     local success, msg = pcall(function()
  234.         AllowDisableCustomAnimsUserFlag = UserSettings():IsUserFeatureEnabled("UserAllowDisableCustomAnims2")
  235.     end)
  236.  
  237.     if (AllowDisableCustomAnimsUserFlag) then
  238.         local success, msg = pcall(function() allowCustomAnimations = game:GetService("StarterPlayer").AllowCustomAnimations end)
  239.         if not success then
  240.             allowCustomAnimations = true
  241.         end
  242.     end
  243.  
  244.     -- check for config values
  245.     local config = script:FindFirstChild(name)
  246.     if (allowCustomAnimations and config ~= nil) then
  247.         table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  248.         table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  249.         local idx = 1
  250.         for _, childPart in pairs(config:GetChildren()) do
  251.             if (childPart:IsA("Animation")) then
  252.                 table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  253.                 animTable[name][idx] = {}
  254.                 animTable[name][idx].anim = childPart
  255.                 local weightObject = childPart:FindFirstChild("Weight")
  256.                 if (weightObject == nil) then
  257.                     animTable[name][idx].weight = 1
  258.                 else
  259.                     animTable[name][idx].weight = weightObject.Value
  260.                 end
  261.                 animTable[name].count = animTable[name].count + 1
  262.                 animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  263.                 idx = idx + 1
  264.             end
  265.         end
  266.     end
  267.  
  268.     -- fallback to defaults
  269.     if (animTable[name].count <= 0) then
  270.         for idx, anim in pairs(fileList) do
  271.             animTable[name][idx] = {}
  272.             animTable[name][idx].anim = Instance.new("Animation")
  273.             animTable[name][idx].anim.Name = name
  274.             animTable[name][idx].anim.AnimationId = anim.id
  275.             animTable[name][idx].weight = anim.weight
  276.             animTable[name].count = animTable[name].count + 1
  277.             animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  278.             -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  279.         end
  280.     end
  281.    
  282.     -- preload anims
  283.     if PreloadAnimsUserFlag then
  284.         for i, animType in pairs(animTable) do
  285.             for idx = 1, animType.count, 1 do
  286.                 Humanoid:LoadAnimation(animType[idx].anim)
  287.             end
  288.         end
  289.     end
  290. end
  291.  
  292. -- Setup animation objects
  293. function scriptChildModified(child)
  294.     local fileList = animNames[child.Name]
  295.     if (fileList ~= nil) then
  296.         configureAnimationSet(child.Name, fileList)
  297.     end
  298. end
  299.  
  300. script.ChildAdded:connect(scriptChildModified)
  301. script.ChildRemoved:connect(scriptChildModified)
  302.  
  303.  
  304. for name, fileList in pairs(animNames) do
  305.     configureAnimationSet(name, fileList)
  306. end
  307.  
  308. -- ANIMATION
  309.  
  310. -- declarations
  311. local toolAnim = "None"
  312. local toolAnimTime = 0
  313.  
  314. local jumpAnimTime = 0
  315. local jumpAnimDuration = 0.31
  316.  
  317. local toolTransitionTime = 0.1
  318. local fallTransitionTime = 0.2
  319.  
  320. local currentlyPlayingEmote = false
  321.  
  322. -- functions
  323.  
  324. function stopAllAnimations()
  325.     local oldAnim = currentAnim
  326.  
  327.     -- return to idle if finishing an emote
  328.     if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  329.         oldAnim = "idle"
  330.     end
  331.    
  332.     if FFlagAnimateScriptEmoteHook and currentlyPlayingEmote then
  333.         oldAnim = "idle"
  334.         currentlyPlayingEmote = false
  335.     end
  336.  
  337.     currentAnim = ""
  338.     currentAnimInstance = nil
  339.     if (currentAnimKeyframeHandler ~= nil) then
  340.         currentAnimKeyframeHandler:disconnect()
  341.     end
  342.  
  343.     if (currentAnimTrack ~= nil) then
  344.         currentAnimTrack:Stop()
  345.         currentAnimTrack:Destroy()
  346.         currentAnimTrack = nil
  347.     end
  348.  
  349.     -- clean up walk if there is one
  350.     if (runAnimKeyframeHandler ~= nil) then
  351.         runAnimKeyframeHandler:disconnect()
  352.     end
  353.    
  354.     if (runAnimTrack ~= nil) then
  355.         runAnimTrack:Stop()
  356.         runAnimTrack:Destroy()
  357.         runAnimTrack = nil
  358.     end
  359.    
  360.     return oldAnim
  361. end
  362.  
  363. function getHeightScale()
  364.     if Humanoid then
  365.         if FFlagUserAdjustHumanoidRootPartToHipPosition then
  366.             if not Humanoid.AutomaticScalingEnabled then
  367.                 return 1
  368.             end
  369.         end
  370.        
  371.         local scale = Humanoid.HipHeight / HumanoidHipHeight
  372.         if userAnimationSpeedDampening then
  373.             if AnimationSpeedDampeningObject == nil then
  374.                 AnimationSpeedDampeningObject = script:FindFirstChild("ScaleDampeningPercent")
  375.             end
  376.             if AnimationSpeedDampeningObject ~= nil then
  377.                 scale = 1 + (Humanoid.HipHeight - HumanoidHipHeight) * AnimationSpeedDampeningObject.Value / HumanoidHipHeight
  378.             end
  379.         end
  380.         return scale
  381.     end
  382.     return 1
  383. end
  384.  
  385. local smallButNotZero = 0.0001
  386. function setRunSpeed(speed)
  387.     local speedScaled = speed * 1.25
  388.     local heightScale = getHeightScale()
  389.     local runSpeed = speedScaled / heightScale
  390.  
  391.     if runSpeed ~= currentAnimSpeed then
  392.         if runSpeed < 0.33 then
  393.             currentAnimTrack:AdjustWeight(1.0)     
  394.             runAnimTrack:AdjustWeight(smallButNotZero)
  395.         elseif runSpeed < 0.66 then
  396.             local weight = ((runSpeed - 0.33) / 0.33)
  397.             currentAnimTrack:AdjustWeight(1.0 - weight + smallButNotZero)
  398.             runAnimTrack:AdjustWeight(weight + smallButNotZero)
  399.         else
  400.             currentAnimTrack:AdjustWeight(smallButNotZero)
  401.             runAnimTrack:AdjustWeight(1.0)
  402.         end
  403.         currentAnimSpeed = runSpeed
  404.         runAnimTrack:AdjustSpeed(runSpeed)
  405.         currentAnimTrack:AdjustSpeed(runSpeed)
  406.     end
  407. end
  408.  
  409. function setAnimationSpeed(speed)
  410.     if currentAnim == "walk" then
  411.             setRunSpeed(speed)
  412.     else
  413.         if speed ~= currentAnimSpeed then
  414.             currentAnimSpeed = speed
  415.             currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  416.         end
  417.     end
  418. end
  419.  
  420. function keyFrameReachedFunc(frameName)
  421.     if (frameName == "End") then
  422.         if currentAnim == "walk" then
  423.             if userNoUpdateOnLoop == true then
  424.                 if runAnimTrack.Looped ~= true then
  425.                     runAnimTrack.TimePosition = 0.0
  426.                 end
  427.                 if currentAnimTrack.Looped ~= true then
  428.                     currentAnimTrack.TimePosition = 0.0
  429.                 end
  430.             else
  431.                 runAnimTrack.TimePosition = 0.0
  432.                 currentAnimTrack.TimePosition = 0.0
  433.             end
  434.         else
  435.             local repeatAnim = currentAnim
  436.             -- return to idle if finishing an emote
  437.             if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
  438.                 repeatAnim = "idle"
  439.             end
  440.            
  441.             if FFlagAnimateScriptEmoteHook and currentlyPlayingEmote then
  442.                 if currentAnimTrack.Looped then
  443.                     -- Allow the emote to loop
  444.                     return
  445.                 end
  446.                
  447.                 repeatAnim = "idle"
  448.                 currentlyPlayingEmote = false
  449.             end
  450.            
  451.             local animSpeed = currentAnimSpeed
  452.             playAnimation(repeatAnim, 0.15, Humanoid)
  453.             setAnimationSpeed(animSpeed)
  454.         end
  455.     end
  456. end
  457.  
  458. function rollAnimation(animName)
  459.     local roll = math.random(1, animTable[animName].totalWeight)
  460.     local origRoll = roll
  461.     local idx = 1
  462.     while (roll > animTable[animName][idx].weight) do
  463.         roll = roll - animTable[animName][idx].weight
  464.         idx = idx + 1
  465.     end
  466.     return idx
  467. end
  468.  
  469. local function switchToAnim(anim, animName, transitionTime, humanoid)
  470.     -- switch animation    
  471.     if (anim ~= currentAnimInstance) then
  472.        
  473.         if (currentAnimTrack ~= nil) then
  474.             currentAnimTrack:Stop(transitionTime)
  475.             currentAnimTrack:Destroy()
  476.         end
  477.  
  478.         if (runAnimTrack ~= nil) then
  479.             runAnimTrack:Stop(transitionTime)
  480.             runAnimTrack:Destroy()
  481.             if userNoUpdateOnLoop == true then
  482.                 runAnimTrack = nil
  483.             end
  484.         end
  485.  
  486.         currentAnimSpeed = 1.0
  487.    
  488.         -- load it to the humanoid; get AnimationTrack
  489.         currentAnimTrack = humanoid:LoadAnimation(anim)
  490.         currentAnimTrack.Priority = Enum.AnimationPriority.Core
  491.          
  492.         -- play the animation
  493.         currentAnimTrack:Play(transitionTime)
  494.         currentAnim = animName
  495.         currentAnimInstance = anim
  496.  
  497.         -- set up keyframe name triggers
  498.         if (currentAnimKeyframeHandler ~= nil) then
  499.             currentAnimKeyframeHandler:disconnect()
  500.         end
  501.         currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  502.        
  503.         -- check to see if we need to blend a walk/run animation
  504.         if animName == "walk" then
  505.             local runAnimName = "run"
  506.             local runIdx = rollAnimation(runAnimName)
  507.  
  508.             runAnimTrack = humanoid:LoadAnimation(animTable[runAnimName][runIdx].anim)
  509.             runAnimTrack.Priority = Enum.AnimationPriority.Core
  510.             runAnimTrack:Play(transitionTime)      
  511.            
  512.             if (runAnimKeyframeHandler ~= nil) then
  513.                 runAnimKeyframeHandler:disconnect()
  514.             end
  515.             runAnimKeyframeHandler = runAnimTrack.KeyframeReached:connect(keyFrameReachedFunc) 
  516.         end
  517.     end
  518. end
  519.  
  520. function playAnimation(animName, transitionTime, humanoid)  
  521.     local idx = rollAnimation(animName)
  522.     local anim = animTable[animName][idx].anim
  523.  
  524.     switchToAnim(anim, animName, transitionTime, humanoid)
  525. end
  526.  
  527. function playEmote(emoteAnim, transitionTime, humanoid)
  528.     switchToAnim(emoteAnim, emoteAnim.Name, transitionTime, humanoid)
  529.     currentlyPlayingEmote = true
  530. end
  531.  
  532. -------------------------------------------------------------------------------------------
  533. -------------------------------------------------------------------------------------------
  534.  
  535. local toolAnimName = ""
  536. local toolAnimTrack = nil
  537. local toolAnimInstance = nil
  538. local currentToolAnimKeyframeHandler = nil
  539.  
  540. function toolKeyFrameReachedFunc(frameName)
  541.     if (frameName == "End") then
  542.         playToolAnimation(toolAnimName, 0.0, Humanoid)
  543.     end
  544. end
  545.  
  546.  
  547. function playToolAnimation(animName, transitionTime, humanoid, priority)           
  548.         local idx = rollAnimation(animName)
  549.         local anim = animTable[animName][idx].anim
  550.  
  551.         if (toolAnimInstance ~= anim) then
  552.            
  553.             if (toolAnimTrack ~= nil) then
  554.                 toolAnimTrack:Stop()
  555.                 toolAnimTrack:Destroy()
  556.                 transitionTime = 0
  557.             end
  558.                    
  559.             -- load it to the humanoid; get AnimationTrack
  560.             toolAnimTrack = humanoid:LoadAnimation(anim)
  561.             if priority then
  562.                 toolAnimTrack.Priority = priority
  563.             end
  564.              
  565.             -- play the animation
  566.             toolAnimTrack:Play(transitionTime)
  567.             toolAnimName = animName
  568.             toolAnimInstance = anim
  569.  
  570.             currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  571.         end
  572. end
  573.  
  574. function stopToolAnimations()
  575.     local oldAnim = toolAnimName
  576.  
  577.     if (currentToolAnimKeyframeHandler ~= nil) then
  578.         currentToolAnimKeyframeHandler:disconnect()
  579.     end
  580.  
  581.     toolAnimName = ""
  582.     toolAnimInstance = nil
  583.     if (toolAnimTrack ~= nil) then
  584.         toolAnimTrack:Stop()
  585.         toolAnimTrack:Destroy()
  586.         toolAnimTrack = nil
  587.     end
  588.  
  589.     return oldAnim
  590. end
  591.  
  592. -------------------------------------------------------------------------------------------
  593. -------------------------------------------------------------------------------------------
  594. -- STATE CHANGE HANDLERS
  595.  
  596. function onRunning(speed)
  597.     if speed > 0.5 then
  598.         local scale = 16.0
  599.         playAnimation("walk", 0.2, Humanoid)
  600.         setAnimationSpeed(speed / scale)
  601.         pose = "Running"
  602.     else
  603.         if emoteNames[currentAnim] == nil then
  604.             playAnimation("idle", 0.2, Humanoid)
  605.             pose = "Standing"
  606.         end
  607.     end
  608. end
  609.  
  610. function onDied()
  611.     pose = "Dead"
  612. end
  613.  
  614. function onJumping()
  615.     playAnimation("jump", 0.1, Humanoid)
  616.     jumpAnimTime = jumpAnimDuration
  617.     pose = "Jumping"
  618. end
  619.  
  620. function onClimbing(speed)
  621.     local scale = 5.0
  622.     playAnimation("climb", 0.1, Humanoid)
  623.     setAnimationSpeed(speed / scale)
  624.     pose = "Climbing"
  625. end
  626.  
  627. function onGettingUp()
  628.     pose = "GettingUp"
  629. end
  630.  
  631. function onFreeFall()
  632.     if (jumpAnimTime <= 0) then
  633.         playAnimation("fall", fallTransitionTime, Humanoid)
  634.     end
  635.     pose = "FreeFall"
  636. end
  637.  
  638. function onFallingDown()
  639.     pose = "FallingDown"
  640. end
  641.  
  642. function onSeated()
  643.     pose = "Seated"
  644. end
  645.  
  646. function onPlatformStanding()
  647.     pose = "PlatformStanding"
  648. end
  649.  
  650. -------------------------------------------------------------------------------------------
  651. -------------------------------------------------------------------------------------------
  652.  
  653. function onSwimming(speed)
  654.     if speed > 1.00 then
  655.         local scale = 10.0
  656.         playAnimation("swim", 0.4, Humanoid)
  657.         setAnimationSpeed(speed / scale)
  658.         pose = "Swimming"
  659.     else
  660.         playAnimation("swimidle", 0.4, Humanoid)
  661.         pose = "Standing"
  662.     end
  663. end
  664.  
  665. function animateTool()
  666.     if (toolAnim == "None") then
  667.         playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
  668.         return
  669.     end
  670.  
  671.     if (toolAnim == "Slash") then
  672.         playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
  673.         return
  674.     end
  675.  
  676.     if (toolAnim == "Lunge") then
  677.         playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
  678.         return
  679.     end
  680. end
  681.  
  682. function getToolAnim(tool)
  683.     for _, c in ipairs(tool:GetChildren()) do
  684.         if c.Name == "toolanim" and c.className == "StringValue" then
  685.             return c
  686.         end
  687.     end
  688.     return nil
  689. end
  690.  
  691. local lastTick = 0
  692.  
  693. function stepAnimate(currentTime)
  694.     local amplitude = 1
  695.     local frequency = 1
  696.     local deltaTime = currentTime - lastTick
  697.     lastTick = currentTime
  698.  
  699.     local climbFudge = 0
  700.     local setAngles = false
  701.  
  702.     if (jumpAnimTime > 0) then
  703.         jumpAnimTime = jumpAnimTime - deltaTime
  704.     end
  705.  
  706.     if (pose == "FreeFall" and jumpAnimTime <= 0) then
  707.         playAnimation("fall", fallTransitionTime, Humanoid)
  708.     elseif (pose == "Seated") then
  709.         playAnimation("sit", 0.5, Humanoid)
  710.         return
  711.     elseif (pose == "Running") then
  712.         playAnimation("walk", 0.2, Humanoid)
  713.     elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  714.         stopAllAnimations()
  715.         amplitude = 0.1
  716.         frequency = 1
  717.         setAngles = true
  718.     end
  719.  
  720.     -- Tool Animation handling
  721.     local tool = Character:FindFirstChildOfClass("Tool")
  722.     if tool and tool:FindFirstChild("Handle") then
  723.         local animStringValueObject = getToolAnim(tool)
  724.  
  725.         if animStringValueObject then
  726.             toolAnim = animStringValueObject.Value
  727.             -- message recieved, delete StringValue
  728.             animStringValueObject.Parent = nil
  729.             toolAnimTime = currentTime + .3
  730.         end
  731.  
  732.         if currentTime > toolAnimTime then
  733.             toolAnimTime = 0
  734.             toolAnim = "None"
  735.         end
  736.  
  737.         animateTool()      
  738.     else
  739.         stopToolAnimations()
  740.         toolAnim = "None"
  741.         toolAnimInstance = nil
  742.         toolAnimTime = 0
  743.     end
  744. end
  745.  
  746. -- connect events
  747. Humanoid.Died:connect(onDied)
  748. Humanoid.Running:connect(onRunning)
  749. Humanoid.Jumping:connect(onJumping)
  750. Humanoid.Climbing:connect(onClimbing)
  751. Humanoid.GettingUp:connect(onGettingUp)
  752. Humanoid.FreeFalling:connect(onFreeFall)
  753. Humanoid.FallingDown:connect(onFallingDown)
  754. Humanoid.Seated:connect(onSeated)
  755. Humanoid.PlatformStanding:connect(onPlatformStanding)
  756. Humanoid.Swimming:connect(onSwimming)
  757.  
  758. -- setup emote chat hook
  759. game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
  760.     local emote = ""
  761.     if (string.sub(msg, 1, 3) == "/e ") then
  762.         emote = string.sub(msg, 4)
  763.     elseif (string.sub(msg, 1, 7) == "/emote ") then
  764.         emote = string.sub(msg, 8)
  765.     end
  766.    
  767.     if (pose == "Standing" and emoteNames[emote] ~= nil) then
  768.         playAnimation(emote, EMOTE_TRANSITION_TIME, Humanoid)
  769.     end
  770. end)
  771.  
  772. -- emote bindable hook
  773. if FFlagAnimateScriptEmoteHook then
  774.     script:WaitForChild("PlayEmote").OnInvoke = function(emote)
  775.         -- Only play emotes when idling
  776.         if pose ~= "Standing" then
  777.             return
  778.         end
  779.    
  780.         if emoteNames[emote] ~= nil then
  781.             -- Default emotes
  782.             playAnimation(emote, EMOTE_TRANSITION_TIME, Humanoid)
  783.            
  784.             return true
  785.         elseif typeof(emote) == "Instance" and emote:IsA("Animation") then
  786.             -- Non-default emotes
  787.             playEmote(emote, EMOTE_TRANSITION_TIME, Humanoid)
  788.             return true
  789.         end
  790.        
  791.         -- Return false to indicate that the emote could not be played
  792.         return false
  793.     end
  794. end
  795.  
  796. -- initialize to idle
  797. playAnimation("idle", 0.1, Humanoid)
  798. pose = "Standing"
  799.  
  800. -- loop to handle timed state transitions and tool animations
  801. while Character.Parent ~= nil do
  802.     local _, currentGameTime = wait(0.1)
  803.     stepAnimate(currentGameTime)
  804. end
  805.  
  806.  
  807. ~~~~~~~~~~~~~~~~~
Advertisement
Add Comment
Please, Sign In to add comment