Hello, I am trying to make a gun with team killing disabled, and I am having trouble. Since to do that I am doing local player = game.Players:GetPlayerFromCharacter(part.Parent) but since that accessories block my raycast bullet, I used mouse.TargetFilter = game:GetService("Players").LocalPlayer but, whenever I shoot the player on his/her accessory, it still messes up. How could I add like two mouse.TargetFilters? Somehow? Someone please help.
Code:
Ammo = 12
damage = 12
AbleToFire = true
Player = game:GetService("Players").LocalPlayer
mouse = Player:GetMouse()
mouse.TargetFilter = Player.Character
script.Parent.Equipped:connect(function(eventMouse)
Player:WaitForChild("PlayerGui").ScreenGui5.Frame.Visible = true
eventMouse.Icon = "rbxasset://textures\\GunCursor.png"
local Arm = Player.Character["Right Arm"]
local Torso = Arm.Parent.Torso
local Weld = Player.Character.Torso:WaitForChild("Weld")
Weld.Part0 = Torso
Weld.Part1 = Arm
Weld.C1 = CFrame.Angles(math.rad(-90), -1, math.rad(0)) * CFrame.new(-1, -0.8, 0.8)
local Weld2 = Player.Character.Torso:WaitForChild("Weld2")
local Arm2 = Player.Character["Left Arm"]
Weld.Part0 = Torso
Weld.Part1 = Arm2
Weld.C1 = CFrame.Angles(math.rad(-90), 1, math.rad(0)) * CFrame.new(-0.3, -0.5, 0.8)
end)
script.Parent.Unequipped:connect(function()
Player:WaitForChild("PlayerGui").ScreenGui5.Frame.Visible = false
local Weld = Player.Character.Torso:WaitForChild("Weld")
Weld.Part0 = nil
Weld.Part1 = nil
end)
script.Parent.Activated:connect(function()
if Ammo > 0 and AbleToFire == true then
if AbleToFire then
script.Parent.FireSound:Play()
local ray = Ray.new(script.Parent.Handle.CFrame.p, (mouse.Hit.p - script.Parent.Handle.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, Player.Character, false, true)
Bullet = Instance.new("Part", workspace)
Bullet.CanCollide = true
Bullet.BrickColor = BrickColor.new("New Yeller")
Bullet.FormFactor = "Custom"
Bullet.Material = "Neon"
Bullet.CanCollide = false
Bullet.Anchored = true
Bullet.Locked = true
Bullet.Name = "M9Bullet"
local distance = (script.Parent.Handle.CFrame.p - position).magnitude
Bullet.Size = Vector3.new(.0500, .0500, distance)
Bullet.CFrame = CFrame.new(script.Parent.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(Bullet, 0.1)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent:FindFirstChild("Humanoid")
end
if humanoid then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player.TeamColor ~= Player.TeamColor then
humanoid:TakeDamage(30)
end
end
end
end
script.Parent.GripPos = Vector3.new(0.15, -0.4, -0.8)
wait(0)
script.Parent.GripPos = Vector3.new(0.15, -0.4, -0.85)
Ammo = Ammo - 1
Player.PlayerGui.ScreenGui5.Ammo.Value = Player.PlayerGui.ScreenGui5.Ammo.Value - 1
AbleToFire = false
wait(.2)
AbleToFire = true
end
end)
mouse.KeyDown:connect(function(Key)
if Key == "r" then
if Ammo <= 11 then
if AbleToFire then
AbleToFire = false
AbleToFire = false
script.Parent.ReloadSound:Play()
wait(1.377)
Ammo = 12
Player.PlayerGui.ScreenGui5.Ammo.Value = 12
AbleToFire = true
end
end
end
end)
