How do I make this detect if a part doesn't contain humanoid?
I am aware that this is a VERY inefficient script, but that's not why its here
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local X = 0
local Debounce = false
local Damage = 0
local Ammount = 0
local Conflict = false
tool.Equipped:connect(function(mouse)
print("Tool equipped!")
01 | mouse.Button 1 Down:connect( function () |
02 | print ( "Mouse pressed!" ) |
03 | if Debounce = = true then |
07 | local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300 ) |
08 | local part, position = workspace:FindPartOnRay(ray, player.Character, false , true ) |
10 | local Charge = Instance.new( "Part" , workspace) |
11 | Charge.BrickColor = BrickColor.new( "Toothpaste" ) |
12 | Charge.Anchored = true |
13 | Charge.Material = "Neon" |
14 | Charge.Transparency = 0.5 |
16 | Charge.CanCollide = false |
17 | Charge.FormFactor = "Custom" |
18 | Charge.CFrame = tool.Handle.CFrame |
19 | Charge.Size = Vector 3. new( 1 , 1 , 1 ) |
20 | local Mesh = Instance.new( "SpecialMesh" , workspace) |
22 | Mesh.MeshType = "Sphere" |
23 | Damage = math.random( 10 , 20 ) |
24 | Ammount = math.random( 1 , 5 ) |
25 | Mesh.Scale = Vector 3. new(X,X,X) -Repeats 40 times |
30 | local beam = Instance.new( "Part" , workspace) |
31 | beam.BrickColor = BrickColor.new( "Toothpaste" ) |
32 | beam.FormFactor = "Custom" |
33 | beam.Material = "Neon" |
34 | beam.Transparency = 0.25 |
37 | beam.CanCollide = false |
39 | local distance = (tool.Handle.CFrame.p - position).magnitude |
40 | beam.Size = Vector 3. new( 0.5 , 0.5 , distance) |
41 | beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new( 0 , 0 , -distance / 2 ) |
43 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
46 | humanoid = part.Parent.Parent:FindFirstChild( "Humanoid" ) |
58 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
59 | beam.Size = Vector 3. new( 3 , 3 , distance) |
60 | while Conflict = = true and Ammount > 0 do |
62 | humanoid:TakeDamage(Damage) |
67 | beam.Size = Vector 3. new( 2.5 , 2.5 , distance) |
68 | beam.Transparency = 0.375 |
69 | Charge.Transparency = 0.375 |
71 | beam.Size = Vector 3. new( 2 , 2 , distance) |
72 | beam.Transparency = 0.5 |
73 | Charge.Transparency = 0.5 |
75 | beam.Size = Vector 3. new( 1.5 , 1.5 , distance) |
76 | beam.Transparency = 0.675 |
77 | Charge.Transparency = 0.675 |
79 | beam.Size = Vector 3. new( 1 , 1 , distance) |
80 | beam.Transparency = 0.75 |
81 | Charge.Transparency = 0.75 |
end)
In short. The laser works if it hits a part containing Humanoid, but it doesn't work if it hits nothing or a part doesn't contain Humanoid