You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to fix my script so player’s can’t kill/damage other player’s that are on the same team
What is the issue? Include screenshots / videos if possible!
The issue is players can damage other players that are on their team resulting in an easy way to get points for your team and/or annoy other players.
The script is more advanced than this but this is the general idea lua RS.shoot.OnServerEvent:Connect(function(player, Target, damage) if player.Team ~= Target.Team then Target.Humanoid.Health -= damage end end)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking for other solutions but I have been unable to find any. I have also tried lua if player.Team == Target.Team then else --damage code end
This has happened before and I forgot to mention it, this makes it so it won’t take damage of off anyone. So if I’m on the red team and I shoot someone on the blue team it won’t take damage off of them either.
I think it was something to do with my server script, so I put the if statement in the local script which fires the server script and it works fine. This is what it looks like:
if Target.Parent:FindFirstChild("Humanoid") then
if game.ReplicatedStorage.MapVoting:FindFirstChild("Storage") and game.ReplicatedStorage.MapVoting.Storage:FindFirstChild("Status") then
local gameStatus = game.ReplicatedStorage.MapVoting.Storage.Status.Value
if gameStatus == "game" then
local shotPlayer = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
if shotPlayer and shotPlayer.Team ~= Player.Team then
local damage
if Mouse.Target.Name == "Head" then
damage = head_damage
else
damage = body_damage
end
game.ReplicatedStorage.shoot:FireServer(Target.Parent, damage)
end
end
else
print("Game status data not found.")
end
end