Roblox · Анимации
G — помахать, H — танец, J — «ура», K — показать рукой. Начал идти — эмоция прекращается. На телефоне — кнопки на экране. По умолчанию стоят стандартные эмоции Roblox, их можно заменить своими.
Синим — что нужно создать.
StarterPlayer └─ StarterCharacterScripts └─ EmotesLocal (LocalScript) └─ Emotes (Folder) └─ Wave, Dance, Cheer, Point (Animation) — атрибуты Key (G, H, J, K) и Title
Где: StarterPlayer → StarterCharacterScripts · LocalScript
Зачем: Эмоции по клавишам и кнопкам.
-- клавиши и кнопки на телефоне
local CAS = game:GetService("ContextActionService")
-- персонаж (скрипт в StarterCharacterScripts)
local character = script.Parent
-- его Humanoid
local humanoid = character:WaitForChild("Humanoid")
-- проигрывает анимации
local animator = humanoid:WaitForChild("Animator")
-- папка с эмоциями
local emotes = script:WaitForChild("Emotes")
-- эмоция, что играет сейчас
local current = nil
-- остановить эмоцию
local function Stop()
-- плавно
if current then current:Stop(0.2) end
-- ничего не играет
current = nil
-- конец функции
end
-- каждая эмоция
for _, anim in ipairs(emotes:GetChildren()) do
-- это анимация
if anim:IsA("Animation") then
-- загружаем
local track = animator:LoadAnimation(anim)
-- главнее стойки и ходьбы
track.Priority = Enum.AnimationPriority.Action
-- клавиша из атрибута Key
local key = Enum.KeyCode[anim:GetAttribute("Key") or "G"]
-- нажали клавишу эмоции
CAS:BindAction("Emote" .. anim.Name, function(_, state)
-- только нажатие
if state ~= Enum.UserInputState.Begin then return end
-- та же эмоция ещё играет
if current == track then
-- второе нажатие — стоп
Stop()
-- готово
return
-- конец проверки
end
-- другую — останавливаем
Stop()
-- запоминаем
current = track
-- играем
track:Play(0.2)
-- true — кнопка на телефоне
end, true, key)
-- надпись на кнопке
CAS:SetTitle("Emote" .. anim.Name, anim:GetAttribute("Title") or anim.Name)
-- конец проверки
end
-- конец перебора
end
-- игрок начал двигаться
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
-- пошёл — эмоция прекращается
if humanoid.MoveDirection.Magnitude > 0.1 then Stop() end
-- конец обработчика
end)
-- прыгнул — тоже
humanoid.Jumping:Connect(Stop)Запусти Play (или Run) и убедись: