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!
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!