I made a script that checks if a part, named Hitbox, touches anything with a humanoid or anything named Hitbox or Blade, but when it checks for an opponent is says "Players.Player1.Backpack.Tool.Handle.Weld.BasicAttack:36: table index is nil" in the output.
BasicAttack = game:GetService("ReplicatedStorage").RemoteFunctions:FindFirstChild("WeaponRemotes").ZangetsuRemotes["BasicAttack"]
Assets = game:GetService("ReplicatedFirst"):WaitForChild("Assets")
BasicAttack.OnServerEvent:connect(function(player)
player.Character.holder.Clashing.Value = true
----------------------------------------------------Variables
local Sword = player.Character.Tool.Blade
local clash = Instance.new('BodyVelocity')
local root = player.Character.HumanoidRootPart
local hitbox = Instance.new("Part", game.Workspace)
local name = player.Name
local folder = game:GetService("ReplicatedStorage"):FindFirstChild(name)
local Kendo = folder.Stats.Kendo
debounce = {};
----------------------------------------------------Hitbox
hitbox.Name = "Hitbox"
hitbox.CFrame = Sword.CFrame
hitbox.CanCollide = false
hitbox.Size = Vector3.new(10,2,1)
hitbox.Transparency = 0.5
hitbox.BrickColor = BrickColor.new("Really red")
---------------------------------------------------Welding
local w1 = Instance.new("Weld", Sword)
w1.Part0 = Sword
w1.Part1 = hitbox
w1.C0 = CFrame.Angles(0,0,5)
w1.C1 = CFrame.new(0,-0.3,0)
--------------------------------------------------Damage
hitbox.Touched:connect(function(hit)
local dmg = math.floor(Kendo.Value/ 1.15 + math.random(1,5))
local enemyWeapon = hit.Parent:findFirstChild('Hitbox')
local opponent = hit.Parent:findFirstChild("Humanoid")
if opponent ~= player.Character.Humanoid and hit.Name ~= "Hitbox" or hit.Parent.Name ~= "Blade" then
if debounce[opponent] then return end;
debounce[opponent] = true;
opponent:TakeDamage(dmg)
------------------------------------------------------
-----------------[Text/Gui and debounce]---------------------------
local effect = Instance.new("BillboardGui", opponent.Parent.Head)
effect.Size = UDim2.new(1,0,1,0)
wait()
local text = Instance.new("TextBox")
text.Parent = effect
text.TextSize = 60
text.TextColor3 = Color3.new(255,255,255)
text.TextStrokeColor3 = Color3.new(95,0,0)
text.TextStrokeTransparency = 0
text.Font = "Cartoon"
text.BackgroundTransparency = 1
text.Size = UDim2.new(1,0,1,0)
text.Text = dmg
wait(0.5)
effect:destroy()
debounce[opponent] = nil;
elseif hit.Parent.Name == 'Hitbox' or hit.Parent.Name == "Blade" then
clash.Parent = root
clash.maxForce = Vector3.new(1e8,1e8,1e8)
clash.Velocity = root.CFrame.lookVector*-60
wait()
clash.Velocity = Vector3.new(0,0,0)
clash:remove()
else
print(hit.Parent.Name)
end
end)
wait(0.85)
hitbox:remove()
wait(0.5)
player.Character.holder.Clashing.Value = false
end)
