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

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.


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

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

1 Like

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.

1 Like

Solved! Thank you so much for help.