Weapon script dosn't deflect damage, why?
I'm trying to make a weapon, it swings but it doesn't do any damage,when I had the script print what the argument was, it said terrain.
console
Terrain
18:33:52.341 - Humanoid is not a valid member of Workspace
18:33:52.342 - Stack Begin
18:33:52.343 - Script 'Players.Player2.Backpack.axe.damage', Line 5
18:33:52.344 - Stack End
script
1 | script.Parent.hitbox.Touched:connect( function (p) |
2 | if script.Parent.CanDamage.Value = = true then |
4 | script.Parent.CanDamage.Value = false |
5 | p.Parent.Humanoid:TakeDamage( 20 ) |
local script
03 | script.Parent.Activated:connect( function () |
05 | local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack) |
07 | if CanAttack = = true then |
08 | script.Parent.CanDamage.Value = true |
09 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0 |
17 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 |
20 | script.Parent.CanDamage.Value = false |
welding script (in case)
001 | local NEVER_BREAK_JOINTS = false |
003 | local function CallOnChildren(Instance, FunctionToCall) |
005 | FunctionToCall(Instance) |
007 | for _, Child in next , Instance:GetChildren() do |
008 | CallOnChildren(Child, FunctionToCall) |
012 | local function GetNearestParent(Instance, ClassName) |
014 | local Ancestor = Instance |
016 | Ancestor = Ancestor.Parent |
017 | if Ancestor = = nil then |
020 | until Ancestor:IsA(ClassName) |
025 | local function GetBricks(StartInstance) |
028 | CallOnChildren(StartInstance, function (Item) |
029 | if Item:IsA( "BasePart" ) then |
030 | List [ #List+ 1 ] = Item; |
037 | local function Modify(Instance, Values) |
039 | assert ( type (Values) = = "table" , "Values is not a table" ); |
041 | for Index, Value in next , Values do |
042 | if type (Index) = = "number" then |
043 | Value.Parent = Instance |
045 | Instance [ Index ] = Value |
051 | local function Make(ClassType, Properties) |
054 | return Modify(Instance.new(ClassType), Properties) |
057 | local Surfaces = { "TopSurface" , "BottomSurface" , "LeftSurface" , "RightSurface" , "FrontSurface" , "BackSurface" } |
058 | local HingSurfaces = { "Hinge" , "Motor" , "SteppingMotor" } |
060 | local function HasWheelJoint(Part) |
061 | for _, SurfaceName in pairs (Surfaces) do |
062 | for _, HingSurfaceName in pairs (HingSurfaces) do |
063 | if Part [ SurfaceName ] .Name = = HingSurfaceName then |
072 | local function ShouldBreakJoints(Part) |
076 | if NEVER_BREAK_JOINTS then |
080 | if HasWheelJoint(Part) then |
084 | local Connected = Part:GetConnectedParts() |
086 | if #Connected = = 1 then |
090 | for _, Item in pairs (Connected) do |
091 | if HasWheelJoint(Item) then |
093 | elseif not Item:IsDescendantOf(script.Parent) then |
101 | local function WeldTogether(Part 0 , Part 1 , JointType, WeldParent) |
103 | JointType = JointType or "Weld" |
104 | local RelativeValue = Part 1 :FindFirstChild( "qRelativeCFrameWeldValue" ) |
106 | local NewWeld = Part 1 :FindFirstChild( "qCFrameWeldThingy" ) or Instance.new(JointType) |
108 | Name = "qCFrameWeldThingy" ; |
112 | C 1 = RelativeValue and RelativeValue.Value or Part 1. CFrame:toObjectSpace(Part 0. CFrame); |
116 | if not RelativeValue then |
117 | RelativeValue = Make( "CFrameValue" , { |
119 | Name = "qRelativeCFrameWeldValue" ; |
128 | local function WeldParts(Parts, MainPart, JointType, DoNotUnanchor) |
130 | for _, Part in pairs (Parts) do |
131 | if ShouldBreakJoints(Part) then |
136 | for _, Part in pairs (Parts) do |
137 | if Part ~ = MainPart then |
138 | WeldTogether(MainPart, Part, JointType, MainPart) |
142 | if not DoNotUnanchor then |
143 | for _, Part in pairs (Parts) do |
144 | Part.Anchored = false |
146 | MainPart.Anchored = false |
150 | local function PerfectionWeld() |
151 | local Tool = GetNearestParent(script, "Tool" ) |
153 | local Parts = GetBricks(script.Parent) |
154 | local PrimaryPart = Tool and Tool:FindFirstChild( "Handle" ) and Tool.Handle:IsA( "BasePart" ) and Tool.Handle or script.Parent:IsA( "Model" ) and script.Parent.PrimaryPart or Parts [ 1 ] |
157 | WeldParts(Parts, PrimaryPart, "Weld" , false ) |
159 | warn( "qWeld - Unable to weld part" ) |
165 | local Tool = PerfectionWeld() |
168 | if Tool and script.ClassName = = "Script" then |
171 | script.Parent.AncestryChanged:connect( function () |