I scripted a gun. On the damage, I don't want it to kill myself. So I set the name of the bullets to the Players name(Owner). However, it does kill me. Any soloutions?
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Activated = true
script.Parent.Equipped:connect(function()
Mouse.Icon = "http://www.roblox.com/asset/?id=59125633"
Activated = false
end)
script.Parent.Unequipped:connect(function()
Activated = true
end)
function Shoot()
print("Shoot")
if Mouse == Player:GetMouse() and script.Parent.Parent.Pistol ~= nil and Activated == false then
local Bullet = Instance.new("Part", workspace)
Bullet.FormFactor = "Custom"
Bullet.Size = Vector3.new(0.3, 0.3, 0.3)
Bullet.TopSurface = "Smooth"
Bullet.Name = Player.Name
Bullet.BottomSurface = "Smooth"
Bullet.Shape = "Ball"
Bullet.CFrame = script.Parent.Handle.CFrame
Bullet.CFrame = CFrame.new(Bullet.Position, Mouse.Hit.p)
Bullet:BreakJoints()
Power = Instance.new("BodyVelocity", Bullet)
Power.maxForce = Vector3.new(math.huge, math.huge, math.huge)
Power.Velocity = Bullet.CFrame.lookVector*1000
Bullet.Touched:connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Name ~= script.Parent.Name then
Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health -40
end
if Hit.Parent:FindFirstChild("Head") and Hit.Parent.Name ~= script.Parent.Name then
Hit.Parent.Humanoid.Health = 0
end
end)
end
end
Mouse.Button1Down:connect(Shoot)
