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

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

Asked by 7 years ago

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!

0
Use if not game.Players:GetPlayerFromCharacter(character) then character:TakeDamage(20) end) If its false then its not a real player! Thetacah 712 — 7y

1 answer

Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
7 years ago

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!

0
Thank you so much for that great info! SIMONking135 0 — 7y
0
hi thetacah ik u posted this 4yrs ago but its totaly not working for me Matheusse0510 0 — 3y
Ad

Answer this question