RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Write me the most complex sword script you can make"
I'm not sure about the "most complex" sword script, but here's a sword script with multiple features such as damage, knockback, and a special ability that can be activated with a cooldown. ```lua -- Server Script local Sword = script.Parent local Handle = Sword.Handle local Damage = 25 local KnockbackForce = 10 local SpecialAbilityCooldown = 5 local SpecialAbilityActive = false local function onTouched(hit) local character = hit.Parent local humanoid = character:FindFirstChild("Humanoid") local swordWielder = Sword.Parent.Parent if humanoid and swordWielder ~= character then humanoid:TakeDamage(Damage) local knockbackDirection = (character.HumanoidRootPart.Position - swordWielder.HumanoidRootPart.Position).Unit character.HumanoidRootPart:SetNetworkOwner(nil) character.HumanoidRootPart.Velocity = knockbackDirection * KnockbackForce end end Handle.Touched:Connect(onTouched) -- Local Script (inside the sword) local Sword = script.Parent local UserInputService = game:GetService("UserInputService") local Cooldown = false local function activateSpecialAbility() if not Cooldown then Cooldown = true Sword.SpecialAbilityEvent:FireServer() wait(Sword.SpecialAbilityCooldown.Value) Cooldown = false end end UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.E and not gameProcessedEvent then activateSpecialAbility() end end) -- Server Script (inside the sword) local Sword = script.Parent local SpecialAbilityDamage = 50 local SpecialAbilityKnockbackForce = 25 local function onSpecialAbilityActivated() local character = Sword.Parent local humanoid = character:FindFirstChild("Humanoid") local target = Sword.Target.Value if target and humanoid then target.Humanoid:TakeDamage(SpecialAbilityDamage) local knockbackDirection = (target.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Unit target.HumanoidRootPart:SetNetworkOwner(nil) target.HumanoidRootPart.Velocity = knockbackDirection * SpecialAbilityKnockbackForce end end Sword.SpecialAbilityEvent.OnServerEvent:Connect(onSpecialAbilityActivated) ``` This script creates a sword that deals damage and applies knockback force to the character it hits. Additionally, it has a special ability that can be activated with the "E" key, dealing increased damage and knockback force with a cooldown between uses.