local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local Debris = game:GetService("Debris") local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local HRP = character:WaitForChild("HumanoidRootPart") local mouse = player:GetMouse() -- Animation IDs local Animations = { Idle = "rbxassetid://18885903667", Walk = "rbxassetid://18885906143", Click = "rbxassetid://18885909645", Q = "rbxassetid://18885932392", R = "rbxassetid://18885915433", T = "rbxassetid://18885919947", Intro = "rbxassetid://18924919303", } -- Audio IDs local Audio = { Intro = "rbxassetid://120121923711079", -- Audio Intro Main = "rbxassetid://109462962253306", -- Background Music sau intro Idle = "rbxassetid://73235255020546", -- Audio cho khi đứng yên Click = "rbxassetid://110759725172567", -- Audio cho chuột trái R = "rbxassetid://88445378869172", -- Audio cho chiêu R T = "rbxassetid://130562515541162", -- Audio cho chiêu T } -- Table chứa các audio đang chạy để cleanup sau này local activeSounds = {} -- Helper: Play sound và theo dõi local function playSound(id, parent, volume, looped) local s = Instance.new("Sound", parent) s.SoundId = id s.Volume = volume or 1 s.Looped = looped or false s:Play() table.insert(activeSounds, s) return s end -- Helper: Cleanup tất cả audio local function clearAllSounds() for _, s in ipairs(activeSounds) do if s and s:IsA("Sound") then s:Stop() s:Destroy() end end activeSounds = {} end -- Helper: Load Animation local function loadAnim(id) local anim = Instance.new("Animation") anim.AnimationId = id return humanoid:LoadAnimation(anim) end -- Load Animations local idleTrack = loadAnim(Animations.Idle) local walkTrack = loadAnim(Animations.Walk) local clickTrack = loadAnim(Animations.Click) local qTrack = loadAnim(Animations.Q) local rTrack = loadAnim(Animations.R) local tTrack = loadAnim(Animations.T) local introTrack = loadAnim(Animations.Intro) -- Play Intro Animation + Audio local introSound = playSound(Audio.Intro, workspace, 1, false) introTrack:Play() local introPlaying = true task.delay(3, function() introTrack:Stop() if introSound then introSound:Stop() end introPlaying = false -- Start background music playSound(Audio.Main, workspace, 1, true) idleTrack:Play() end) -- Idle / Walk handling local idleAudio = nil RunService.RenderStepped:Connect(function() if introPlaying then return end if humanoid.MoveDirection.Magnitude > 0 then if not walkTrack.IsPlaying then walkTrack:Play() end if idleTrack.IsPlaying then idleTrack:Stop() end if idleAudio then idleAudio:Stop() idleAudio:Destroy() idleAudio = nil end else if not idleTrack.IsPlaying then idleTrack:Play() end if walkTrack.IsPlaying then walkTrack:Stop() end if not idleAudio then idleAudio = playSound(Audio.Idle, workspace, 0.6, true) end end end) -- Input handling UserInputService.InputBegan:Connect(function(input, gameProcessed) if introPlaying or gameProcessed then return end if input.UserInputType == Enum.UserInputType.MouseButton1 then local s = playSound(Audio.Click, workspace, 1, false) clickTrack:Play() clickTrack.Stopped:Connect(function() s:Stop() s:Destroy() end) elseif input.KeyCode == Enum.KeyCode.Q then qTrack:Play() local dash = Instance.new("BodyVelocity") dash.MaxForce = Vector3.new(1, 1, 1) * 100000 dash.Velocity = HRP.CFrame.LookVector * 60 dash.P = 50 dash.Parent = HRP local connection connection = HRP.Touched:Connect(function(hit) if hit:IsA("BasePart") and hit.CanCollide and not hit:IsDescendantOf(char) then dash:Destroy() connection:Disconnect() end end) Debris:AddItem(dash, 0.9) elseif input.KeyCode == Enum.KeyCode.R then -- Chiêu R: chỉ chạy animation và audio, không khóa chuyển động rTrack:Play() local rSound = playSound(Audio.R, workspace, 1, false) rTrack.Stopped:Connect(function() rSound:Stop() rSound:Destroy() end) elseif input.KeyCode == Enum.KeyCode.T then -- Chiêu T: tương tự chiêu R tTrack:Play() local tSound = playSound(Audio.T, workspace, 1, false) tTrack.Stopped:Connect(function() tSound:Stop() tSound:Destroy() end) end end) -- Khi nhân vật chết, xoá hết âm thanh humanoid.Died:Connect(function() if idleAudio then idleAudio:Stop() idleAudio:Destroy() idleAudio = nil end clearAllSounds() idleTrack:Stop() walkTrack:Stop() clickTrack:Stop() qTrack:Stop() rTrack:Stop() tTrack:Stop() introTrack:Stop() end) player.CharacterAdded:Connect(function(newChar) newChar:WaitForChild("Humanoid").Died:Connect(function() clearAllSounds() end) end)