You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to achieve anti team kill in my gun system. -
What is the issue? Include screenshots / videos if possible!
I dont know how to detect what team the plr is. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried checking if the team is similiar to the enemy then did a return end before i apply damage in the server script but it didnt work.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local configuration = require(script.Parent.Settings)
script.Parent.Ammo.Value = configuration.ammo
local mag = script.Parent:WaitForChild("Mag")
local debounce = false
script.Parent.Configuration.RemoteEvents.Fire.OnServerEvent:Connect(function(plr, mousePos)
local blacklist = {plr.Character}
for i, v in pairs(game.Workspace:GetChildren()) do
local hum = v:FindFirstChild("Humanoid")
if hum then
if hum.Health == 0 then
table.insert(blacklist, v)
end
end
end
local recoils = {0.1,0.2,0.3,-0.1,-0.2,-0.3}
local recoilsY = {0,0.1,0.2,0.3,0.4,0.5,0.6}
local xRecoil = recoils[math.random(1, #recoils)]
local yRecoil = recoils[math.random(1, #recoilsY)]
local zRecoil = recoils[math.random(1, #recoils)]
script.Parent.Ammo.Value -= 1
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = blacklist
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
if configuration.shotgun == false then
local raycastResult = workspace:Raycast(plr.Character.Head.Position, ((mousePos+Vector3.new(xRecoil,yRecoil,zRecoil)) - plr.Character.Head.Position)*configuration.range, raycastParams)
if raycastResult then
game.ReplicatedStorage.GunSystem.ClientEvents.Fire:FireAllClients(raycastResult.Position, script.Parent, configuration.shotgun, raycastResult)
local hitpart = raycastResult.Instance
local model = hitpart:FindFirstAncestorOfClass("Model") or hitpart:FindFirstAncestorOfClass("Tool") or hitpart:FindFirstAncestorOfClass("Accessory")
if model then
if model:FindFirstChild("Humanoid") or model.Parent:FindFirstChild("Humanoid") or model.Parent.Parent:FindFirstChild("Humanoid") then
if model:FindFirstChild("Humanoid") then
if model.Humanoid.Health <= configuration.damage and model.Humanoid.Health ~= 0 then
script.Parent.Configuration.RemoteEvents.Kill:FireClient(plr, "NOOB", model.Humanoid.Parent.Name)
game.ReplicatedStorage.GunSystem.ClientEvents.Kill:FireAllClients(plr.Name, model.Humanoid.Parent.Name)
end
model.Humanoid.Health -= configuration.damage
elseif model.Parent:FindFirstChild("Humanoid") then
if model.Parent.Humanoid.Health <= configuration.damage and model.Parent.Humanoid.Health ~= 0 then
script.Parent.Configuration.RemoteEvents.Kill:FireClient(plr, "NOOB", model.Parent.Humanoid.Parent.Name)
game.ReplicatedStorage.GunSystem.ClientEvents.Kill:FireAllClients(plr.Name, model.Parent.Humanoid.Parent.Name)
end
model.Parent.Humanoid.Health -= configuration.damage
elseif model.Parent.Parent:FindFirstChild("Humanoid") then
if model.Parent.Parent.Humanoid.Health <= configuration.damage and model.Parent.Parent.Humanoid.Health ~= 0 then
script.Parent.Configuration.RemoteEvents.Kill:FireClient(plr, "NOOB", model.Parent.Parent.Humanoid.Parent.Name)
game.ReplicatedStorage.GunSystem.ClientEvents.Kill:FireAllClients(plr.Name, model.Parent.Parent.Humanoid.Parent.Name)
end
model.Parent.Parent.Humanoid.Health -= configuration.damage
end
game.ReplicatedStorage.GunSystem.ClientEvents.HumanoidHit:FireAllClients(hitpart, raycastResult.Normal, raycastResult.Position)
end
end
if not hitpart.Parent:FindFirstChild("Humanoid") or not model.Parent:FindFirstChild("Humanoid") or not model.Parent.Parent:FindFirstChild("Humanoid") and not hitpart.Name == "HumanoidRootPart" then
game.ReplicatedStorage.GunSystem.ClientEvents.PartHit:FireAllClients(hitpart, raycastResult.Normal, raycastResult.Position)
end
else
game.ReplicatedStorage.GunSystem.ClientEvents.Fire:FireAllClients(mousePos, script.Parent, configuration.shotgun)
end
else
for i = 1, configuration.pellet_ammount do
local raycastResult = workspace:Raycast(plr.Character.Head.Position, ((mousePos+Vector3.new(math.random(0.5,2),math.random(0.5,2),math.random(0.5,2))) - plr.Character.Head.Position)*configuration.range, raycastParams)
if raycastResult then
game.ReplicatedStorage.GunSystem.ClientEvents.Fire:FireAllClients(raycastResult.Position, script.Parent, configuration.shotgun, raycastResult)
local hitpart = raycastResult.Instance
local model = hitpart:FindFirstAncestorOfClass("Model") or hitpart:FindFirstAncestorOfClass("Tool") or hitpart:FindFirstAncestorOfClass("Accessory")
if model then
if model:FindFirstChild("Humanoid") or model.Parent:FindFirstChild("Humanoid") or model.Parent.Parent:FindFirstChild("Humanoid") then
if model:FindFirstChild("Humanoid") then
if model.Humanoid.Health <= configuration.damage and model.Humanoid.Health ~= 0 then
script.Parent.Configuration.RemoteEvents.Kill:FireClient(plr, "NOOB", model.Humanoid.Parent.Name)
game.ReplicatedStorage.GunSystem.ClientEvents.Kill:FireAllClients(plr.Name, model.Humanoid.Parent.Name)
end
model.Humanoid.Health -= configuration.damage
elseif model.Parent:FindFirstChild("Humanoid") then
if model.Parent.Humanoid.Health <= configuration.damage and model.Parent.Humanoid.Health ~= 0 then
script.Parent.Configuration.RemoteEvents.Kill:FireClient(plr, "NOOB", model.Parent.Humanoid.Parent.Name)
game.ReplicatedStorage.GunSystem.ClientEvents.Kill:FireAllClients(plr.Name, model.Parent.Humanoid.Parent.Name)
end
model.Parent.Humanoid.Health -= configuration.damage
elseif model.Parent.Parent:FindFirstChild("Humanoid") then
if model.Parent.Parent.Humanoid.Health <= configuration.damage and model.Parent.Parent.Humanoid.Health ~= 0 then
script.Parent.Configuration.RemoteEvents.Kill:FireClient(plr, "NOOB", model.Parent.Parent.Humanoid.Parent.Name)
game.ReplicatedStorage.GunSystem.ClientEvents.Kill:FireAllClients(plr.Name, model.Parent.Parent.Humanoid.Parent.Name)
end
model.Humanoid.Health -= configuration.damage
end
game.ReplicatedStorage.GunSystem.ClientEvents.HumanoidHit:FireAllClients(hitpart, raycastResult.Normal, raycastResult.Position)
end
end
if not hitpart.Parent:FindFirstChild("Humanoid") or not model.Parent:FindFirstChild("Humanoid") or not model.Parent.Parent:FindFirstChild("Humanoid") and not hitpart.Name == "HumanoidRootPart" then
game.ReplicatedStorage.GunSystem.ClientEvents.PartHit:FireAllClients(hitpart, raycastResult.Normal, raycastResult.Position)
end
else
game.ReplicatedStorage.GunSystem.ClientEvents.Fire:FireAllClients(mousePos, script.Parent, configuration.shotgun)
end
end
end
end)
local folder = Instance.new("Folder")
folder.Name = "FakeMags"
script.Parent.Configuration.RemoteEvents.Reload.OnServerEvent:Connect(function()
if configuration.magdrop == true then
local magclone = mag:Clone()
magclone.Parent = workspace
magclone.Anchored = false
magclone.CanCollide = true
mag.Transparency = 1
game:GetService("Debris"):AddItem(magclone,6)
print("mag Transparency = 1")
script.Parent.Handle.Reload:Play()
wait(configuration.reload)
script.Parent.Ammo.Value = configuration.ammo
mag.Transparency = 0
print("mag Transparency = 0")
end
if configuration.magdrop == false then
print("magdrop false")
script.Parent.Handle.Reload:Play()
wait(configuration.reload)
script.Parent.Ammo.Value = configuration.ammo
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.