Unkillable player

I was going to make a pvp off/on button but I think people will find ways to abuse it so I just want to make it were players cant kill other players at all but still the NPCS
Everything I find is out of date or not what im looking for, that why i’m asking here.
do I need to make one?
If I do where should the script go in starter player or workspace
how should I format it?
Do I have to put anything in my tools (im not good with tools)

You could tag the NPCs using Collection Service, then when a player tries doing damage to an enemy, make sure the enemy has the NPC tag. (This will make it so you can’t deal damage to players)

1 Like

When damaging a target, check if the target is a player’s character. Do something like this;

local Players = game:GetService("Players");
function damageTarget(target, damage)
	local plr = Players:GetPlayerFromCharacter(target);
	local hum = target:FindFirstChildOfClass("Humanoid");
	if not plr then
		hum:TakeDamage(damage);
	end
end

Players:GetPlayerFromCharacter() will return a player from a given model instance. If it’s not a character, it returns nil, meaning that it’s an NPC.

1 Like

I believe what you can do is if a player has there pvp set to disabled you can go into the players humanoid and set there MaxHealth and Health to a super high number (or use Math.Huge). Or you can create a table of people who there pvp and make it so that if a players userid is in they get hit.

(Feel free to mark this as a solution if this helped.)

Thank you @ellienonekomimi it worked for me!
and thank you @TheAnimeDev28 it did help but the thing Im trying to so it would not work as planed and @ellienonekomimi I did not want to make a pvp buttons bc players can use that to camp and stuff but thanks anyways!

1 Like