RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"code a sword slash ability"
```lua -- local script for sword slash ability local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local debounce = false local function onActivated() if debounce then return end debounce = true -- Perform slash animation local animation = Instance.new("Animation") animation.AnimationId = "rbxassetid://SlashAnimationId" -- Replace with actual animation asset id local animTrack = player.Character.Humanoid:LoadAnimation(animation) animTrack:Play() -- Detect if the slash hits any targets local hitBox = tool:WaitForChild("HitBox") -- Assuming there's a part named HitBox within the tool local connection connection = hitBox.Touched:Connect(function(hit) local hitCharacter = hit.Parent local humanoid = hitCharacter:FindFirstChildWhichIsA("Humanoid") if humanoid and hitCharacter ~= player.Character then -- Apply damage or effect to the humanoid humanoid.Health = humanoid.Health - 25 -- Example damage end end) -- Wait for the animation to finish before disconnecting the Touched event animTrack.Stopped:Wait() connection:Disconnect() debounce = false end tool.Activated:Connect(onActivated) ```