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!")
mouse.Button1Down:connect(function() print("Mouse pressed!") if Debounce == true then return end Debounce = true local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300) local part, position = workspace:FindPartOnRay(ray, player.Character, false, true) local Charge = Instance.new("Part", workspace) Charge.BrickColor = BrickColor.new("Toothpaste") Charge.Anchored = true Charge.Material = "Neon" Charge.Transparency = 0.5 Charge.Locked = true Charge.CanCollide = false Charge.FormFactor = "Custom" Charge.CFrame = tool.Handle.CFrame Charge.Size = Vector3.new(1,1,1) local Mesh = Instance.new("SpecialMesh", workspace) Mesh.Parent = Charge Mesh.MeshType = "Sphere" Damage = math.random(10,20) Ammount = math.random(1,5) Mesh.Scale = Vector3.new(X,X,X) -Repeats 40 times X = X + 0.2 wait() local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Toothpaste") beam.FormFactor = "Custom" beam.Material = "Neon" beam.Transparency = 0.25 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (tool.Handle.CFrame.p - position).magnitude beam.Size = Vector3.new(0.5, 0.5, distance) beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) if part then --Problem area local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") Ammount = 0 Conflict = false end if humanoid then Conflict = true end else Ammount = 0 Conflict = false end local humanoid = part.Parent:FindFirstChild("Humanoid") beam.Size = Vector3.new(3, 3, distance) while Conflict == true and Ammount > 0 do wait(0.1) humanoid:TakeDamage(Damage) Ammount = Ammount - 1 end wait(Ammount+1) Conflict = false beam.Size = Vector3.new(2.5, 2.5, distance) beam.Transparency = 0.375 Charge.Transparency = 0.375 wait() beam.Size = Vector3.new(2, 2, distance) beam.Transparency = 0.5 Charge.Transparency = 0.5 wait() beam.Size = Vector3.new(1.5, 1.5, distance) beam.Transparency = 0.675 Charge.Transparency = 0.675 wait() beam.Size = Vector3.new(1, 1, distance) beam.Transparency = 0.75 Charge.Transparency = 0.75 wait() beam:Destroy() Charge:Destroy() X = 0 wait(5) Debounce = false end) --Problem Area End
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