well here we go, ive been trying to make a fps game and ive ran into a issue, team kill, it would be a really big issue due to greifers and stuff, ive tried writing down my own anti team kill on the onrayhit function but it doesnt seem to work, when i treid testing on a alt i could still kill players on the same team and my code dint work,
ive tried many stuff alredy like searching dev forum and switching lines of code
game.ReplicatedStorage.Events.Gunfire.OnServerEvent:Connect(function(player, MuzzlePos, mousePos, damage, limbDMG, CF, muzvel)
local sound = player.Character.Torso:FindFirstChild("Fire")
if sound then
sound:Play()
end
castParams.FilterDescendantsInstances = {player.Character}
castBehaviour.AutoIgnoreContainer = false
castBehaviour.RaycastParams = castParams
local origin = MuzzlePos
local direction = (mousePos - origin)
caster:Fire(origin, direction, muzvel, castBehaviour)
caster.LengthChanged:Connect(onLenghtChanged)
local function onrayHit(cast, castResult, Velocity, flyingthing)
if not hitDebounce[caster] then
hitDebounce[caster] = {[flyingthing] = true}
elseif hitDebounce[caster][flyingthing] then
return
else
hitDebounce[caster][flyingthing] = true
end
flyingthing:Destroy()
local hit = castResult.Instance
local char = hit:FindFirstAncestorWhichIsA("Model")
if not char:FindFirstChild("Humanoid") then
local bulletHole = game.ReplicatedStorage.Effects.BulletHole:Clone()
bulletHole.Parent = game.Workspace.Decos
bulletHole.Name = player.Name .. "_BulletHole"
bulletHole.CFrame = CFrame.new(castResult.Position, castResult.Position + castResult.Normal) * CFrame.new(0, 0, 0)
game.Debris:AddItem(bulletHole, 10)
end
print(hit.Name)
if hit.Name == "HumanoidRootPart" or hit.Name == "Torso" or hit.Name == "Handle" and char:FindFirstChild("Humanoid") and char.Name ~= player.Name then
if player.Team or game:GetService("Players"):GetPlayerFromCharacter(char) == nil then
char.Humanoid:TakeDamage(damage)
elseif player.Team and game:GetService("Players"):GetPlayerFromCharacter(char) and game:GetService("Players"):GetPlayerFromCharacter(char).Team ~= player.Team then
if char:WaitForChild("Armor") then
if char:WaitForChild("Armor").Value == 0 then
char.Humanoid:TakeDamage(damage)
elseif char:WaitForChild("Armor").Value == 1 then
local fixedDamage = damage - 30
char.Humanoid:TakeDamage(fixedDamage)
elseif char:WaitForChild("Armor").Value == 2 then
local fixedDamage = damage - 60
char.Humanoid:TakeDamage(fixedDamage)
elseif char:WaitForChild("Armor").Value == 3 then
local fixedDamage = damage - 70
char.Humanoid:TakeDamage(fixedDamage)
end
end
end
elseif char and char.Name ~= player.Name and hit.Name == "Left Arm" or hit.Name == "Left Leg" or hit.Name == "Right Arm" or hit.Name == "Right Leg" then
if game:GetService("Players"):GetPlayerFromCharacter(char) == nil then
char.Humanoid:TakeDamage(limbDMG)
elseif game:GetService("Players"):GetPlayerFromCharacter(char) and game:GetService("Players"):GetPlayerFromCharacter(char).Team ~= player.Team then
char.Humanoid:TakeDamage(limbDMG)
end
elseif char and hit.Name == "Head" and char.Name ~= player.Name then
if game:GetService("Players"):GetPlayerFromCharacter(char) == nil then
char.Humanoid:TakeDamage(100)
elseif game:GetService("Players"):GetPlayerFromCharacter(char) and game:GetService("Players"):GetPlayerFromCharacter(char).Team ~= player.Team then
char.Humanoid:TakeDamage(100)
end
end
end
caster.RayHit:Connect(onrayHit)
--wait(0.2)
--whiz:Play()
game.Debris:AddItem(bullet, 25)
end)
this is my code so far, it fires and bullet and listens for when it has hit the target, i also added armor values to balance gameplay and stuff they dont work too but i think i could figure it out for myself after the team kill stuff is figured out