local collectionService = game:GetService("CollectionService")
task.wait(3)
for _, characters in pairs(collectionService:GetTagged("Characters")) do
task.spawn(function()
local hum = characters:WaitForChild("Humanoid")
local anim = hum:WaitForChild("Animation")
local animTrack = hum:LoadAnimation(anim)
animTrack.Looped = true
animTrack.Priority = Enum.AnimationPriority.Idle
task.wait(1)
animTrack:Play()
end)
end
my animations are working looped as expected on roblox studio but in the game for once. idk why that happens. do you guys have any idea to solve this?
As a tough fix since you already are using CollectionService, you can also use this as a localscript.
local CollectionService = game:GetService("CollectionService")
local tag = "Characters"
local function onAddedToCharacter(item)
if x and x:IsA("AnimationTrack") then
x.Looped=true
end
end
-- Save the connections so they can be disconnected when the tag is removed
local connections = {}
local function onInstanceAdded(object)
connections[object] = object.ChildAdded:Connect(onAddedToCharacter)
local animationTrack=object:FindFirstChildOfClass("AnimationTrack")
if animationTrack then
onAddedToCharacter(animationTrack)
end
end
local function onInstanceRemoved(object)
-- If there is a stored connection on this object, disconnect/remove it
if connections[object] then
connections[object]:Disconnect()
connections[object] = nil
end
end
-- Listen for this tag being applied to objects
CollectionService:GetInstanceAddedSignal(tag):Connect(onInstanceAdded)
CollectionService:GetInstanceRemovedSignal(tag):Connect(onInstanceRemoved)
-- Also detect any objects that already have the tag
for _, object in pairs(CollectionService:GetTagged(tag)) do
onInstanceAdded(object)
end