I am making an anti team kill script for a gun model. In my script, it successfully finds the team of both the shooter and the person hit and prints them, so I know there isn’t an issue with that. The issue seems to be on inflicting damage itself.
There are four teams: Killer, Game, SWAT, and Lobby.
However, I am having trouble inflicting damage on the appropriate teams. I tried many methods, but I have had no luck. Here is my script so far. There is no errors in output.
function OnRayHit(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
local hitPart = rayResult.Instance
if hitPart ~= nil and hitPart.Parent ~= nil then
local humanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
local shooter = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
local result = game:GetService("Players"):GetPlayerFromCharacter(hitPart.Parent)
print(shooter.Team)
print(result.Team)--prints on server not client so remember when testing
---------------- 4 teams
if shooter.Team == "Lobby" then
return
end
------------
if shooter.Team == "Game" then
if result.Team == shooter.Team then
humanoid:TakeDamage(34) -- Damage.
end
if result.Team == "Killer" then
humanoid:TakeDamage(34) -- Damage.
end
end
-------------
if shooter.Team == "SWAT" then
if result.Team == "Killer" then
humanoid:TakeDamage(34) -- Damage.
end
end
---------------
if shooter.Team == "Killer" then
if result.Team == "Game" then
humanoid:TakeDamage(34) -- Damage.
end
if result.Team == "SWAT" then
humanoid:TakeDamage(34) -- Damage.
end
end
end
end
I’m positive this is an issue with my if then statements for each team. Can somebody help me with this?