Ive tried different outcomes but none of them work please help!!
‘’’ lua
local Figure = script.Parent
local Torso = Figure:WaitForChild(“Torso”)
local RightShoulder = Torso:WaitForChild(“Right Shoulder”)
local LeftShoulder = Torso:WaitForChild(“Left Shoulder”)
local RightHip = Torso:WaitForChild(“Right Hip”)
local LeftHip = Torso:WaitForChild(“Left Hip”)
local Neck = Torso:WaitForChild(“Neck”)
local Humanoid = Figure:WaitForChild(“Humanoid”)
local pose = “Standing”
local currentAnim = “”
local currentAnimInstance = nil
local currentAnimTrack = nil
local currentAnimKeyframeHandler = nil
local currentAnimSpeed = 1.0
local animTable = {}
local animNames = {
idle = {
{ id = “rbxassetid://13987087883”, weight = 9 },
{ id = “rbxassetid://13987087883”, weight = 1 }
},
walk = {
{ id = “rbxassetid://13986932417”, weight = 10 }
},
run = {
{ id = “rbxassetid://13987100745”, weight = 10 }
},
jump = {
{ id = “rbxassetid://13987092539”, weight = 10 }
},
fall = {
{ id = “rbxassetid://13987084105”, weight = 10 }
},
climb = {
{ id = “rbxassetid://13987079980”, weight = 10 }
},
sit = {
{ id = “rbxassetid://13987116682”, weight = 10 }
},
toolnone = {
{ id = “rbxassetid://13987119950”, weight = 10 }
},
}
local dances = { “dance1”, “dance2”, “dance3” }
function configureAnimationSet(name, fileList)
if animTable[name] ~= nil then
for _, connection in pairs(animTable[name].connections) do
connection:Disconnect()
end
end
animTable[name] = {}
animTable[name].count = 0
animTable[name].totalWeight = 0
animTable[name].connections = {}
-- check for config values
local config = script:FindFirstChild(name)
if config ~= nil then
table.insert(animTable[name].connections, config.ChildAdded:Connect(function(child)
configureAnimationSet(name, fileList)
end))
table.insert(animTable[name].connections, config.ChildRemoved:Connect(function(child)
configureAnimationSet(name, fileList)
end))
local idx = 1
for _, childPart in pairs(config:GetChildren()) do
if childPart:IsA("Animation") then
table.insert(animTable[name].connections, childPart.Changed:Connect(function(property)
configureAnimationSet(name, fileList)
end))
animTable[name][idx] = {}
animTable[name][idx].anim = childPart
local weightObject = childPart:FindFirstChild("Weight")
if weightObject == nil then
animTable[name][idx].weight = 1
else
animTable[name][idx].weight = weightObject.Value
end
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
idx = idx + 1
end
end
end
-- fallback to defaults
if animTable[name].count <= 0 then
for idx, anim in pairs(fileList) do
animTable[name][idx] = {}
animTable[name][idx].anim = Instance.new("Animation")
animTable[name][idx].anim.Name = name
animTable[name][idx].anim.AnimationId = anim.id
animTable[name][idx].weight = anim.weight
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
end
end
end
– Setup animation objects
function scriptChildModified(child)
local fileList = animNames[child.Name]
if fileList ~= nil then
configureAnimationSet(child.Name, fileList)
end
end
script.ChildAdded:Connect(scriptChildModified)
script.ChildRemoved:Connect(scriptChildModified)
– Clear any existing animation tracks
– Fixes issue with characters that are moved in and out of the Workspace accumulating tracks
local animator = Humanoid:FindFirstChildOfClass(“Animator”)
if animator then
local animTracks = animator:GetPlayingAnimationTracks()
for i, track in ipairs(animTracks) do
track:Stop(0)
track:Destroy()
end
end
for name, fileList in pairs(animNames) do
configureAnimationSet(name, fileList)
end
– ANIMATION
– declarations
local toolAnim = “None”
local toolAnimTime = 0
local jumpAnimTime = 0
local jumpAnimDuration = 0.3
local toolTransitionTime = 0.1
local fallTransitionTime = 0.3
local jumpMaxLimbVelocity = 0.75
– functions
local emoteNames = {}
function stopAllAnimations()
local oldAnim = currentAnim
-- return to idle if finishing an emote
if emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false then
oldAnim = "idle"
end
currentAnim = ""
currentAnimInstance = nil
if currentAnimKeyframeHandler ~= nil then
currentAnimKeyframeHandler:Disconnect()
end
if currentAnimTrack ~= nil then
currentAnimTrack:Stop()
currentAnimTrack:Destroy()
currentAnimTrack = nil
end
return oldAnim
end
function setAnimationSpeed(speed)
if speed ~= currentAnimSpeed then
currentAnimSpeed = speed
currentAnimTrack:AdjustSpeed(currentAnimSpeed)
end
end
function keyFrameReachedFunc(frameName)
if frameName == “End” then
local repeatAnim = currentAnim
– return to idle if finishing an emote
if emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false then
repeatAnim = “idle”
end
local animSpeed = currentAnimSpeed
playAnimation(repeatAnim, 0.0, Humanoid)
setAnimationSpeed(animSpeed)
end
end
– Preload animations
function playAnimation(animName, transitionTime, humanoid)
local roll = math.random(1, animTable[animName].totalWeight)
local origRoll = roll
local idx = 1
while roll > animTable[animName][idx].weight do
roll = roll - animTable[animName][idx].weight
idx = idx + 1
end
local anim = animTable[animName][idx].anim
-- switch animation
if anim ~= currentAnimInstance then
if currentAnimTrack ~= nil then
currentAnimTrack:Stop(transitionTime)
currentAnimTrack:Destroy()
end
currentAnimSpeed = 1.0
-- load it to the humanoid; get AnimationTrack
currentAnimTrack = humanoid:LoadAnimation(anim)
currentAnimTrack.Priority = Enum.AnimationPriority.Core
-- play the animation
currentAnimTrack:Play(transitionTime)
currentAnim = animName
currentAnimInstance = anim
-- set up keyframe name triggers
if currentAnimKeyframeHandler ~= nil then
currentAnimKeyframeHandler:Disconnect()
end
currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:Connect(keyFrameReachedFunc)
end
end
local toolAnimName = “”
local toolAnimTrack = nil
local toolAnimInstance = nil
local currentToolAnimKeyframeHandler = nil
function toolKeyFrameReachedFunc(frameName)
if frameName == “End” then
playToolAnimation(toolAnimName, 0.0, Humanoid)
end
end
function playToolAnimation(animName, transitionTime, humanoid, priority)
local roll = math.random(1, animTable[animName].totalWeight)
local origRoll = roll
local idx = 1
while roll > animTable[animName][idx].weight do
roll = roll - animTable[animName][idx].weight
idx = idx + 1
end
local anim = animTable[animName][idx].anim
if toolAnimInstance ~= anim then
if toolAnimTrack ~= nil then
toolAnimTrack:Stop()
toolAnimTrack:Destroy()
transitionTime = 0
end
-- load it to the humanoid; get AnimationTrack
toolAnimTrack = humanoid:LoadAnimation(anim)
if priority then
toolAnimTrack.Priority = priority
end
-- play the animation
toolAnimTrack:Play(transitionTime)
toolAnimName = animName
toolAnimInstance = anim
currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:Connect(toolKeyFrameReachedFunc)
end
end
function stopToolAnimations()
local oldAnim = toolAnimName
if currentToolAnimKeyframeHandler ~= nil then
currentToolAnimKeyframeHandler:Disconnect()
end
toolAnimName = ""
toolAnimInstance = nil
if toolAnimTrack ~= nil then
toolAnimTrack:Stop()
toolAnimTrack:Destroy()
toolAnimTrack = nil
end
return oldAnim
end
function onRunning(speed)
if speed > 0.01 then
playAnimation(“walk”, 0.1, Humanoid)
if currentAnimInstance and currentAnimInstance.AnimationId == “rbxassetid://180426354” then
setAnimationSpeed(speed / 14.5)
end
pose = “Running”
else
if emoteNames[currentAnim] == nil then
playAnimation(“idle”, 0.1, Humanoid)
pose = “Standing”
end
end
end
function onDied()
pose = “Dead”
end
function onJumping()
playAnimation(“jump”, 0.1, Humanoid)
jumpAnimTime = jumpAnimDuration
pose = “Jumping”
end
function onClimbing(speed)
playAnimation(“climb”, 0.1, Humanoid)
setAnimationSpeed(speed / 12.0)
pose = “Climbing”
end
function onGettingUp()
pose = “GettingUp”
end
function onFreeFall()
if jumpAnimTime <= 0 then
playAnimation(“fall”, fallTransitionTime, Humanoid)
end
pose = “FreeFall”
end
function onFallingDown()
pose = “FallingDown”
end
function onSeated()
pose = “Seated”
end
function onPlatformStanding()
pose = “PlatformStanding”
end
function onSwimming(speed)
if speed > 0 then
pose = “Running”
else
pose = “Standing”
end
end
function getTool()
for _, kid in ipairs(Figure:GetChildren()) do
if kid.ClassName == “Tool” then
return kid
end
end
return nil
end
function getToolAnim(tool)
for _, c in ipairs(tool:GetChildren()) do
if c.Name == “toolanim” and c.ClassName == “StringValue” then
return c
end
end
return nil
end
function animateTool()
if toolAnim == “None” then
playToolAnimation(“toolnone”, toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
return
end
if toolAnim == "Slash" then
playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
return
end
if toolAnim == "Lunge" then
playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
return
end
end
– Assuming ‘character’ is a reference to the character model or humanoid
– Helper function to get the character from a player
local function getCharacter(player)
local character = player.Character
if character then
return character
else
player.CharacterAdded:Wait()
return player.Character
end
end
– Function to move the character into a sitting pose
local function moveSit(character)
local char = script.Parent
local rightArm = char:FindFirstChild(“Right Arm”)
local leftArm = char:FindFirstChild(“Left Arm”)
local rightLeg = char:FindFirstChild(“Right Leg”)
local leftLeg = char:FindFirstChild(“Left Leg”)
local torso = char:FindFirstChild(“Torso”)
rightArm.MaxVelocity = 0.15
leftArm.MaxVelocity = 0.15
rightArm:SetDesiredAngle(math.pi / 2)
leftArm:SetDesiredAngle(-math.pi / 2)
torso:SetDesiredAngle(math.pi / 4)
rightLeg:SetDesiredAngle(math.pi / 4)
leftLeg:SetDesiredAngle(-math.pi / 4)
end
– Function to move the character into a standing pose
local function moveStand(character)
local char = script.Parent
local rightArm = char:FindFirstChild(“Right Arm”)
local leftArm = char:FindFirstChild(“Left Arm”)
local rightLeg = char:FindFirstChild(“Right Leg”)
local leftLeg = char:FindFirstChild(“Left Leg”)
local torso = char:FindFirstChild(“Torso”)
rightArm.MaxVelocity = 0.5
leftArm.MaxVelocity = 0.5
rightArm:SetDesiredAngle(0)
leftArm:SetDesiredAngle(0)
torso:SetDesiredAngle(0)
rightLeg:SetDesiredAngle(0)
leftLeg:SetDesiredAngle(0)
end
– Function to move the character into a jumping pose
local function moveJump(character)
local char = script.Parent
local rightArm = char:FindFirstChild(“Right Arm”)
local leftArm = char:FindFirstChild(“Left Arm”)
local rightLeg = char:FindFirstChild(“Right Leg”)
local leftLeg = char:FindFirstChild(“Left Leg”)
local torso = char:FindFirstChild(“Torso”)
rightArm.MaxVelocity = 0.15
leftArm.MaxVelocity = 0.15
rightArm:SetDesiredAngle(math.pi / 2)
leftArm:SetDesiredAngle(-math.pi / 2)
torso:SetDesiredAngle(0)
rightLeg:SetDesiredAngle(0)
leftLeg:SetDesiredAngle(0)
end
– Function to move the character into a falling pose
local function moveFall(character)
local char = script.Parent
local rightArm = char:FindFirstChild(“Right Arm”)
local leftArm = char:FindFirstChild(“Left Arm”)
local rightLeg = char:FindFirstChild(“Right Leg”)
local leftLeg = char:FindFirstChild(“Left Leg”)
local torso = char:FindFirstChild(“Torso”)
rightArm.MaxVelocity = 0.5
leftArm.MaxVelocity = 0.5
rightArm:SetDesiredAngle(0)
leftArm:SetDesiredAngle(0)
torso:SetDesiredAngle(0)
rightLeg:SetDesiredAngle(0)
leftLeg:SetDesiredAngle(0)
end
– Function to move the character into a landed pose
local function moveLanded(character)
local char = script.Parent
local rightArm = char:FindFirstChild(“Right Arm”)
local leftArm = char:FindFirstChild(“Left Arm”)
local rightLeg = char:FindFirstChild(“Right Leg”)
local leftLeg = char:FindFirstChild(“Left Leg”)
local torso = char:FindFirstChild(“Torso”)
rightArm.MaxVelocity = 0.5
leftArm.MaxVelocity = 0.5
rightArm:SetDesiredAngle(0)
leftArm:SetDesiredAngle(0)
torso:SetDesiredAngle(0)
rightLeg:SetDesiredAngle(0)
leftLeg:SetDesiredAngle(0)
end
– Main program
– Get the local player
local localPlayer = game.Players.LocalPlayer
– Define a table to store the characters of other players
local otherCharacters = {}
– Function to handle player added event
local function onPlayerAdded(player)
local character = getCharacter(player)
otherCharacters[player] = character
end
– Function to handle player removing event
local function onPlayerRemoving(player)
otherCharacters[player] = nil
end
– Function to handle humanoid state changes
local function onStateChanged(oldState, newState)
local character = getCharacter(localPlayer)
if newState == Enum.HumanoidStateType.Sitting then
moveSit(character)
elseif newState == Enum.HumanoidStateType.Jumping then
moveJump(character)
elseif newState == Enum.HumanoidStateType.Freefall then
moveFall(character)
elseif newState == Enum.HumanoidStateType.Landed then
moveLanded(character)
else
moveStand(character)
end
end
– Connect events for the local player
localPlayer.CharacterAdded:Connect(function(character)
moveStand(character)
character.Humanoid.StateChanged:Connect(onStateChanged)
end)
– Connect events for other players
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
for _, player in ipairs(game.Players:GetPlayers()) do
if player ~= localPlayer then
onPlayerAdded(player)
end
end
– Start the main loop
– Start the main loop
while true do
– Update the state of other player characters
for player, character in pairs(otherCharacters) do
if character then
local humanoid = character.Humanoid
local state = humanoid:GetState()
if state == Enum.HumanoidStateType.Sitting then
moveSit(character)
elseif state == Enum.HumanoidStateType.Jumping then
moveJump(character)
elseif state == Enum.HumanoidStateType.Freefall then
moveFall(character)
elseif state == Enum.HumanoidStateType.Landed then
moveLanded(character)
else
moveStand(character)
end
end
end
-- Update the state of the local player character
if localPlayer.Character then
local humanoid = localPlayer.Character.Humanoid
local currentState = humanoid:GetState()
if currentState == Enum.HumanoidStateType.Running then
onRunning(humanoid.WalkSpeed)
elseif currentState == Enum.HumanoidStateType.Jumping then
onJumping()
elseif currentState == Enum.HumanoidStateType.Freefall then
onFreeFall()
elseif currentState == Enum.HumanoidStateType.Seated then
onSeated()
elseif currentState == Enum.HumanoidStateType.Swimming then
onSwimming(humanoid.WalkSpeed)
else
moveStand(localPlayer.Character)
end
end
wait(0.1)
end