Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to disable pvp? but still be able to kill zombies

I have searched everywhere on the internet but nothing found. I have seached on YouTube, Google(Found something but didnt really help me) and ROBLOX Studio free models. My goal is to disable pvp for all players but you can still use swords and guns to kill zombies.

I have tryed scripting but im not that good.

I thought of something like making the sword/gun not hit humans, but zombies already has a humanoid inside, so that didnt work out.

Please help!

1 comment

0

Use if not game.Players:GetPlayerFromCharacter(character) then character:TakeDamage(20) end) If its false then its not a real player!

1 answer

To accomplish this, you could use the handy dandy method :GetPlayerFromCharacter(). What that method does is ensures if a character is an actual player or an NPC(Zombie in your case).

To give an example of this, I inserted the generic classic paintball gun you can find under ROBLOX sets in the toolbox. In the Paintball script of this gun, its where we use the .Touched event on the bullet.(Gets cloned into the bullet)

The block of code that manages damage to the humanoid in that script is as followed:

	if humanoid ~= nil 
		tagHumanoid(humanoid)
		humanoid:TakeDamage(damage)
		wait(2)
		untagHumanoid(humanoid)
	end


That code will take damage on both players and Zombies. To fix that, we will use GetPlayerFromCharacter() method.

You would change the if statement to this:

if(humanoid~=nil and  not game.Players:GetPlayerFromCharacter(hit.Parent)) then

That code checks if hit.Parent(which would be the legs,arms,head or torso's Parent(Character)) is indeed a player. We use not which basically reverts the statement, so if its not a player.

The final block of code should look like this:


	if humanoid ~= nil and not game.Players:GetPlayerFromCharacter(hit.Parent) then
		tagHumanoid(humanoid)
		humanoid:TakeDamage(damage)
		wait(2)
		untagHumanoid(humanoid)
	end



Cheers!

2 comments

0

Thank you so much for that great info!

0

hi thetacah ik u posted this 4yrs ago but its totaly not working for me

This discussion is preserved as it was. New answers, comments, and votes are closed.