How to return character to idle state upon unequipping tool
Also the reason i initially stop all animations is because it causes my animation to meditate weird. I’ve tried using different priorities ect.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Remotes = RS.Remotes
local ServerRemotes = Remotes.Server
local SEvents = ServerRemotes.Events
local UnequipCon = nil
local MeditateAnim = Instance.new("Animation")
MeditateAnim.AnimationId = "rbxassetid://120256448672747"
local MeditateAnimTrack, Character
local function OnEquip()
Character = Player.Character
if not Character then return end
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
-- Stop all other animations
for _, track in ipairs(Animator:GetPlayingAnimationTracks()) do
track:Stop()
end
-- Load and play the meditation animation
MeditateAnimTrack = Animator:LoadAnimation(MeditateAnim)
MeditateAnimTrack.Priority = Enum.AnimationPriority.Action3
MeditateAnimTrack.Looped = true
MeditateAnimTrack:Play()
-- Anchor character's primary part to prevent movement
Character.PrimaryPart.Anchored = true
-- Continuously fire the server event while the tool is equipped
while not script.Parent.Parent:IsA("Backpack") do
SEvents.Meditate:FireServer()
task.wait(1)
end
end
local function OnUnequip()
-- Stop the meditation animation
if MeditateAnimTrack then
MeditateAnimTrack:Stop()
end
-- Un-anchor the character's primary part to allow movement
if Character and Character.PrimaryPart then
Character.PrimaryPart.Anchored = false
end
end
script.Parent.Equipped:Connect(OnEquip)
script.Parent.Unequipped:Connect(OnUnequip)