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

How to make a system for not attacking friendlies?

Asked by 3 years ago

I'm making a game where not only your team is friendly with you and I've tried making a system where you cant attack friendlies. The system uses an intvalue and if your team intvalue is the same as another team, you can't attack each other. For some reason it doesn't work.

Server Script:

game.ReplicatedStorage.ShootEvent.OnServerEvent:Connect(function(Player, MouseT, MouseP)
    if MouseT:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid") and Player.Team.TeamAlly.Value ~= game.Players:GetPlayerFromCharacter(MouseT:FindFirstAncestorOfClass("Model")).Team.TeamAlly.Value then 
        MouseT:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid").Health -= 20
    end
end)

Local script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

script.Parent.Equipped:Connect(function()
    Player.CameraMode = Enum.CameraMode.LockFirstPerson
end)

script.Parent.Unequipped:Connect(function()
    Player.CameraMode = Enum.CameraMode.Classic
end)

script.Parent.Activated:Connect(function()
    game.ReplicatedStorage.ShootEvent:FireServer(Mouse.Target, Mouse.Hit.Position)
    print("Hello")
end)

Answer this question