What? Pls Fix This Idk How To
01 | local tool = script.Parent |
02 |
03 | local function onTouch(partOther) |
04 |
05 | local humanOther = partOther.Parent:FindFirstChild( "Humanoid" ) |
06 |
07 | if not humanOther then return end |
08 |
09 | if humanOther.Parent = = tool then return end |
10 |
11 | humanOther:TakeDamage( 25 ) |
12 | end |
13 |
14 | tool.Activated:Connect(onTouch) |
This should happen when the sword touches something, since that will tell the part that touched it
1 | tool.Touched:Connect(onTouch) |
edit: also place this script in the weapon's handle
The error is in the line:
1 | tool.Activated:Connect(onTouch) |
The function onTouch has one parameter: partOther. When the tool is activated, you called the function onTouch, but you didn't give it any parameters. Therefore partOther would be nil. Fix:
01 | local tool = script.Parent |
02 |
03 | local function onTouch(partOther) |
04 |
05 | local humanOther = partOther.Parent:FindFirstChild( "Humanoid" ) |
06 |
07 | if not humanOther then return end |
08 |
09 | if humanOther.Parent = = tool then return end |
10 |
11 | humanOther:TakeDamage( 25 ) |
12 | end |
13 |
14 | tool.Activated:Connect(onTouch( 'whatever partOther is' )) |