Error: Workspace.Sword.SwordScript:37: attempt to index local 'hitBindable' (a nil value)
local DebrisService = game:GetService("Debris") local PlayersService = game:GetService('Players') local damage = 10 local SLASH_DAMAGE = 40.5 local LUNGE_DAMAGE = 54 local OVERHEAD_SLASH_DAMAGE = 90 local Tool = script.Parent local Handle = Tool:WaitForChild('Handle') local MyCharacter local MyHumanoid local PlaySlash local PlayThrust local PlayOverhead local AttackSequence = {} local SlashSound = Handle:WaitForChild('SlashSound') local OverheadSound = Handle:WaitForChild('OverheadSound') local LungeSound = Handle:WaitForChild('LungeSound') local UnsheathSound = Handle:WaitForChild('UnsheathSound') local HitSound = Handle:WaitForChild('HitSound') local HitCharacters local CreatorTag = nil function Blow(hit) if (hit.Parent == nil) then return end local humanoid = hit.Parent:findFirstChild("Humanoid") local vCharacter = Tool.Parent local hum = vCharacter:findFirstChild("Humanoid") if humanoid~=nil and humanoid ~= hum and hum ~= nil and HitCharacters and not HitCharacters[humanoid.Parent] and hum.Health>0 then local right_arm = vCharacter:findFirstChild("Right Arm") if (right_arm ~= nil) then local joint = right_arm:findFirstChild("RightGrip") if (joint ~= nil and (joint.Part0 == Handle or joint.Part1 == Handle)) then HitCharacters[humanoid.Parent] = true local hitBindable = humanoid:findFirstChild('Hit') if hitBindable then HitSound:Play() end hitBindable:Invoke(damage, CreatorTag) else print("Could not find BindableFunction 'Hit'") end end end end function Attack() damage = SLASH_DAMAGE SlashSound:play() if PlaySlash then PlaySlash.Value = not PlaySlash.Value end wait(0.6) end function OverheadSlash() damage = OVERHEAD_SLASH_DAMAGE if PlayOverhead then PlayOverhead.Value = not PlayOverhead.Value end LungeSound:play() local force = Instance.new("BodyVelocity") force.velocity = Vector3.new(0,10,0) DebrisService:AddItem(force, 0.5) force.Parent = Tool.Parent.Torso wait(0.6) end function Lunge() damage = LUNGE_DAMAGE OverheadSound:Play() if PlayThrust then PlayThrust.Value = not PlayThrust.Value end wait(.45) swordOut() wait(.05) if force then force.Parent = nil end wait(.15) swordUp() damage = SLASH_DAMAGE end function swordUp() Tool.GripForward = Vector3.new(1,0,0) Tool.GripRight = Vector3.new(0,0,1) Tool.GripUp = Vector3.new(0,1,0) end function swordOut() Tool.GripForward = Vector3.new(0,-1,0) Tool.GripRight = Vector3.new(0,0,1) Tool.GripUp = Vector3.new(-1,0,0) end table.insert(AttackSequence, Attack) table.insert(AttackSequence, Lunge) table.insert(AttackSequence, OverheadSlash) local CurrentIndex = 1 local LastAttackTime = tick() Tool.Enabled = true function OnActivated() if Tool.Parent:IsA('Model') and Tool.Enabled and MyCharacter and MyHumanoid and MyHumanoid.Health > 0 then Tool.Enabled = false HitCharacters = {[MyCharacter] = true} local now = tick() if now - LastAttackTime > 1.5 then CurrentIndex = 1 else CurrentIndex = CurrentIndex + 1 end LastAttackTime = now if CurrentIndex > #AttackSequence then CurrentIndex = 1 end AttackSequence[CurrentIndex]() if MyHumanoid == nil then print("Humanoid not found") return end HitCharacters = nil Tool.Enabled = true end end function OnEquipped() Tool.GripPos = Vector3.new(0, -1.7, 0) delay(0.55, function() UnsheathSound:play() end) MyCharacter = Tool.Parent MyHumanoid = MyCharacter:FindFirstChild('Humanoid') PlaySlash = Tool:WaitForChild('PlaySlash') PlayOverhead = Tool:WaitForChild('PlayOverhead') PlayThrust = Tool:WaitForChild('PlayThrust') CreatorTag.Value = PlayersService:GetPlayerFromCharacter(MyCharacter) end CreatorTag = Instance.new('ObjectValue') CreatorTag.Name = 'creator' Tool.Activated:connect(OnActivated) Tool.Equipped:connect(OnEquipped) connection = Handle.Touched:connect(Blow)
Look at your tabbing around the use of hitBindable
.
There's an end
that stops the if
immediately before you use hitBindable
(even though it may be nil
).
You should reindent your code and then correct it to use the correct grouping (that end
doesn't belong there -- find out where it does belong, which may jut be the line below).
Maybe because HitBindable is local. Try removing local and see if that works.