I’ve been making a sword script, but I keep getting an error that keeps showing up.
Script:
local Character = player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local debounce = false
local sword = Character:WaitForChild("Sword", 1)
local RaycastHitbox = require(workspace.RaycastHitboxV3)
local Damage = 20
wait(2)
local blade = sword.Blade
local Hitbox = RaycastHitbox:Initialize(blade, {Character})
local replicatedStorage = game.ReplicatedStorage
local particlepart = replicatedStorage["Particle Part"]
mouse.KeyDown:Connect(function(key)
if key == "f" then
if not debounce then
debounce = true
local humanoid = Character.Humanoid
local Animations = Character.Animations
local animatior = humanoid.Animator
local Animation = animatior:LoadAnimation(Animations.swip)
Hitbox:HitStart()
Animation:Play()
blade.Swipe:Play()
wait(.5)
Animation:Stop()
Hitbox:HitStop()
debounce = false
end
end
end)
Hitbox.OnHit:Connect(function(hit)
print(hit.Name)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local particle = particlepart.Spark:Clone()
particle.Parent = hit
humanoid:TakeDamage(Damage)
blade.Hit:Play()
particle.ParticleEmitter:Emit(10)
wait(1)
particle:Destroy()
end)
game:GetService("RunService").RenderStepped:Connect(function()
local character = game.Players.LocalPlayer.Character
repeat wait() until character:FindFirstChild("Sword")
local sword = character:FindFirstChild("Sword")
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("MeshPart") then
-- Remember that LTM is a multiplier; 0-values will not force different transparency
if debounce then
part.LocalTransparencyModifier = 0
blade.Trail.Enabled = true
blade.Blue.Enabled = true
else
part.LocalTransparencyModifier = 1
blade.Blue.Enabled = false
blade.Trail.Enabled = false
end
end
end
end)
Error: [16:05:38.017 - Players.DullXxxswagfoxyxxX.PlayerScripts.Sword:10: attempt to index nil with 'Blade']