Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Anti team kill gun not working?

Asked by 6 years ago

local tool = script.Parent local player = game:GetService("Players").LocalPlayer local t = player.Team print(t) tool.Equipped:connect(function(mouse) print("Tool equipped!") mouse.Button1Down:connect(function() print("Mouse pressed!") local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300) local part, position = workspace:FindPartOnRay(ray, player.Character, false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Brick yellow") beam.FormFactor = "Custom" beam.Material = "Plastic" beam.Transparency = 0.25 beam.Anchored = true beam.Locked = true beam.CanCollide = false beam.FrontSurface = "Smooth" beam.BackSurface = "Smooth" beam.LeftSurface = "Smooth" beam.RightSurface = "Smooth" beam.BottomSurface = "Smooth" beam.TopSurface = "Smooth" local distance = (tool.Handle.CFrame.p - position).magnitude beam.Size = Vector3.new(0.3, 0.3, distance) beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) game:GetService("Debris"):AddItem(beam, 0.1) if part then local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") end if humanoid then if humanoid.Parent then local p = (game.Players:GetPlayerFromCharacter(humanoid.Parent)) print(p.Team) if p == t then humanoid:TakeDamage(0) end else end humanoid:TakeDamage(30) end end end) end)

t stores the players team and p is the targets team. It still damages players of the same team what matter what I do. Any idea? - Thanks

0
You need to look at your if statment logic. You only want to take damage if the teams are different. User#5423 17 — 6y
0
Ive tried making it ~= but that didnt work birdeater11 14 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Try putting this into your script:

local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player.TeamColor ~= vPlayer.TeamColor then 
    tagHumanoid(humanoid, vPlayer)
    humanoid:TakeDamage(damage)
    wait(1)
    untagHumanoid(humanoid)
end
0
i hope this works for you VeryWowMuchDoge 47 — 6y
Ad

Answer this question