so im making an emote tool, and this is what i have so far
i kind of tried to chatgpt my way through this cause just couldnt figure out why it did that at all
heres the script it made me, must be a mess
– SERVICES
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
– TOOL & ANIMATIONS
local tool = script.Parent
– Main animation (required)
local mainAnim = tool:WaitForChild(“Animation”)– Freeze animation (optional)
local freezeAnim = tool:FindFirstChild(“FreezeIdle”)
– TRACK VARIABLES
local mainTrack – Holds currently playing main animation
local freezeTrack – Holds currently playing freeze animation
local mainEndedConnection – Holds Ended event for main animation
– STATE
local equipped = false – Track whether the tool is equipped
local FADE_TIME = 0.2 – Smooth fade in/out for animations
– PLAY ANIMATION FUNCTION
– Plays an animation smoothly
– @param animInstance Animation object
– @param looped Boolean for looping
– @param speed Animation speed multiplier
– @param priority Animation priority enum
– @param fadeTime Optional fade duration
local function playAnimation(animInstance, looped, speed, priority, fadeTime)
local animator = humanoid:FindFirstChildOfClass(“Animator”)
if not animator then return end
if animInstance.AnimationId == “” then
warn(“Animation”, animInstance.Name, “has no AnimationId!”)
return
endlocal track = animator:LoadAnimation(animInstance)
track.Priority = priority or track.Priority
track.Looped = looped or false
if speed then track:AdjustSpeed(speed) end
track:Play(fadeTime or FADE_TIME)
return track
end
– PLAY FREEZE ANIMATION (OPTIONAL)
– Stops existing freeze animation and plays it looping
local function playFreezeAnimation()
if not freezeAnim then return end
if freezeTrack then
freezeTrack:Stop(FADE_TIME)
freezeTrack = nil
end
freezeTrack = playAnimation(freezeAnim, true, 1, Enum.AnimationPriority.Action2, FADE_TIME)
end
– PLAY MAIN ANIMATION
– Stops existing main animation and plays it
– Sets up freeze animation to play when main ends
local function playMainAnimation()
– Stop main track if it exists
if mainTrack then
mainTrack:Stop(FADE_TIME)
mainTrack = nil
end– Disconnect any previous Ended event to prevent stacking
if mainEndedConnection then
mainEndedConnection:Disconnect()
mainEndedConnection = nil
end– Play main animation
mainTrack = playAnimation(mainAnim, false, 1, Enum.AnimationPriority.Action, FADE_TIME)– Connect freeze animation on main animation end
if freezeAnim then
mainEndedConnection = mainTrack.Ended:Connect(function()
if not equipped then return end
playFreezeAnimation()
end)
end
end
– TOOL EQUIPPED
tool.Equipped:Connect(function()
equipped = true
playMainAnimation() – Trigger main animation on equip
end)
– TOOL UNEQUIPPED
tool.Unequipped:Connect(function()
equipped = false– Stop main animation if playing
if mainTrack then
mainTrack:Stop(FADE_TIME)
mainTrack = nil
end– Stop freeze animation if playing
if freezeTrack then
freezeTrack:Stop(FADE_TIME)
freezeTrack = nil
end– Disconnect main Ended connection
if mainEndedConnection then
mainEndedConnection:Disconnect()
mainEndedConnection = nil
end
end)
