I made a AK-47 that can shoot rapidly when Its clicked and hold, the gun also damages players or NPCS when clicked (If the AK-47 Is equipped ofc), and as the name says, I decided to modify It so It doesn't damages teammates, however It lose Its damage feature, meaning It won't damage players anymore
Script (Server script):
local tool = script.Parent
local Shoot = tool.Shooting
local PewAnimation = tool.Animation
tool.Fire.OnServerEvent:Connect(function(player,mousePos)
local Player1 = game.Players:GetPlayerFromCharacter(player,mousePos)
local Player2 = game.Players:GetPlayerFromCharacter(player,mousePos)
local Humanoid = tool.Parent.Humanoid
local AnimationTrack = Humanoid:LoadAnimation(PewAnimation)
AnimationTrack:Play()
Shoot:Play()
local raycastParams = RaycastParams:new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResault = workspace:Raycast(tool.Handle.Position,(mousePos - tool.Handle.Position)*1000,raycastParams)
if raycastResault then
if Player1.TeamColor ~= Player2.TeamColor then
local hitpart = raycastResault.Instance
local model = hitpart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Head") then
model.Humanoid.Health -= math.random(1,2)
end
end
end
end
end)
