How to make the gun killing only people in other team?

Hi!
So for a few days now I have a problem with gun killing people in the same teams. I would like the gun to kill people only in different teams. E.G. If the person with glock is in the “police” team, he/she couldn’t kill other people in “police” team, but can kill people in “prisoners” team.
Solved!

2 Likes

Have you considered using the team property in players?

A general baseline for your code would probably look something like this:

local Player = game.Players.LocalPlayer
local OtherPlayer = game.Players:GetPlayerFromCharacter(Hit.Parent);

if (Player.Team ~= OtherPlayer.Team) then
    --// Do stuff
end
2 Likes

After that, the glock works. After one shoot it freezes and won’t work anymore.
Error:
Players.dan_kulik.Backpack.Glock.GunScript_Local:119: attempt to index nil with ‘Team’

Did you add a check to verify that your script indeed returns a player as its hit object?
If you did, try sending the code here.

Solved! Thank you so much for help.