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

How would I make it so attacks don't hurt the user? (Filtering Enabled)

I am having trouble making it so if an attack is casted by a person, the damage won't hurt the user. I've originally tried making it where the damage brick's parent is the char and if the brick touches the user it references whether or not it's the parent's humanoid. This works in studio and the problem of self-harm is fixed but for some reason, in-game the bricks just end up being invisible to other players . Not sure if this is something that has to do with Filtering Enabled but I'm wondering if there are other ways to turn off self-harm to attacks.

2 answers

You could add a a creator value in the user, it can be any value like:

local creator = Instance.new("IntValue") -- IntValue
local player = game.Players.LocalPlayer -- the user
creator.Name = (player.Name) -- setting the value to the players name, so it doesnt get mixed up
creator.Parent = player.Character -- putting it in the player

and if the attack tries to damage the user you can make a if statment in the damage script like this:

script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild(player.Name):IsA("IntValue") then -- makes sures if its the right value
print("lol dont attack me") -- change this
else 
print("good boy") -- change this
end

this is what most weapons use lol, idk if it works bc i just made it up lol, hope it helpssssssss and change it to fit your script.

7 comments

0

Dear EXpodo1234ALT, you just copied that from somewhere else, didn't you?

0

In the line 2, of your first script, it doesn't know what a Player is.

0

In the line 1, of your second script, it doesn't know what a Player is, and since the first script is not working, the second won't work.

0

Bad practice and he can just put it where if its the local player it dont harm u

0

i was giving an example and that what most weapons use as i said in the question and sorry for not being clear on the player part lol

0

if u said i copied it from somewhere else look at the end

0

did u even read it

Hello, NikkoTheJesusMan!

I had the same problem, until i found a way to prevent it!

So, let me give you an EXAMPLE :

script.Parent.Touched:Connect(function(hit) -- Example, put this as a LocalScript in a weapon!
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= game.Players.LocalPlayer.Name then -- If the player's name isn't same as the tool user then...
-- Do the things you want to do!
hit.Parent.Humanoid:TakeDamage(10)
end)

-- Note: Didn't check on studio!
-- This is just an example!

So, the second line detects if there is a HUMANOID and the player's name is same as the tool user!

-- Hope i helped, if you had other problems then, comment them!

---- AIphanium.

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