duvida, esse script para de ser executado quando o jogador clicar em enviar/fechar/parar…
- User
duvida, esse script para de ser executado quando o jogador clicar em enviar/fechar/parar de digitar/morre/reincia ? ou fica rodando em loop ? se sim, como faço para otimizar ? : local player = game.Players.LocalPlayer local TextBox = script.Parent -- Ajuste se o script não for um filho direto do TextBox
-- Substitua pelo ID real da sua animação local animationId = "rbxassetid://131028936257839" local Animation = Instance.new("Animation") Animation.AnimationId = animationId
-- Obter o SoundService local SoundService = game:GetService("SoundService")
-- Nome do som existente no SoundService local soundName = "TypingSound" -- Certifique-se de que o som tenha este nome no SoundService
-- Variáveis para gerenciar animação e entrada local animationTrack local keysPressed = 0 -- Contador para teclas atualmente pressionadas (PC) local debounce = false local isAnimationPlaying = false
local RunService = game:GetService("RunService") local lastTextChangeTime = nil local typingStopDelay = 0.75 -- Tempo após o qual consideramos que a digitação parou (mobile)
-- RemoteEvent para gerenciamento de acessório local ReplicatedStorage = game:GetService("ReplicatedStorage") local AccessoryEvent = ReplicatedStorage:WaitForChild("AccessoryEvent") local lastAccessoryEventTime = 0 local accessoryEventCooldown = 0.5 -- Envia notificação de digitação no máximo a cada 0.5 segundos
-- Obter o som existente no SoundService local typingSound = SoundService.Efeitos_Sonoros:FindFirstChild(soundName) if not typingSound then warn("Som '" .. soundName .. "' não encontrado no SoundService.") end
local function playAnimation() if not isAnimationPlaying then -- Tocar a animação local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") -- Usar WaitForChild para garantir que o Humanoid exista if humanoid then animationTrack = humanoid:LoadAnimation(Animation) animationTrack:Play() isAnimationPlaying = true end
code-- Tocar o som existente no SoundService if typingSound then if not typingSound.IsPlaying then typingSound:Play() end end endend
local function stopAnimation() if isAnimationPlaying then if animationTrack then animationTrack:Stop() animationTrack:Destroy() animationTrack = nil end isAnimationPlaying = false end
code-- Parar o som quando a animação parar if typingSound and typingSound.IsPlaying then typingSound:Stop() endend
-- Função para lidar com InputBegan no TextBox (para PC) local function onInputBegan(input) if input.UserInputType == Enum.UserInputType.Keyboard then keysPressed = keysPressed + 1 if not debounce then debounce = true playAnimation()
- Assistant