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

How to remove local damage?

I just want this to players can kill NPCs but can't kill other players.

1 answer

There are multiple ways of doing this, but the best and simplest way to do this without messing with the vital core scripts that run ROBLOX.

Rename the Humanoid objects within the NPCs, e.g. "Monster" or "Enemy" are good examples, but keep it consistent just like Humanoid objects would be without your meddling. After this, go into your weapons or means of damaging health and ensure that it attacks a humanoid object named with your new name instead of the usual "Humanoid." I.e. the code for a weapon (abstractly) could be...

-- ...
-- Damaging health... (where npc = the NPC model)
local humanoid = npc:FindFirstChild("NAME") -- replace 'NAME' with the new name for the humanoid, e.g. Monster (ensuring that it's something already found in a character)
if humanoid:IsA("Humanoid") then
	humanoid:TakeDamage(...) -- the usual business goes here
end
-- ...

This'll avoid all humanoid objects not called NAME, including the "Humanoid" which exist naturally within the players.

If this doesn't help, try adding code that checks whether the character being attacked is a player, using the GetPlayerFromCharacter function of game.Players (returns nil is not a player).

2 comments

0

Thanks bro! :D

0

You're very welcome mate :)

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