What I tried:
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
function Fired()
local bullet = Instance.new("Part", script.Parent)
bullet.CFrame = script.Parent.Handle.CFrame
local bulletmesh = Instance.new("CylinderMesh", bullet)
bullet.Size = Vector3.new(0.9, 0.4, 0.4)
bullet.Rotation = Vector3.new(0, 0, -96.521)
local b = Instance.new("BodyPosition", bullet)
bullet.Name = "Projectile"
bullet.BrickColor = BrickColor.Black()
b.maxForce = Vector3.new(100000,100000,100000)
b.Position = mouse.Hit.p
--THIS PART
function onhit(hit)
if bullet.Position == mouse.Target.Position then
mouse.Target.Humanoid.Health = mouse.Target.Humanoid.Health - 20
end
end
bullet.Touched:connect(onhit)
end
mouse.Button1Down:connect(Fired)
And it failed.. can you help me?
