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

How do i make the player not take damage from his own abilities?

basically if the player goes into the abilities area of damage they also take damage how am i able to prevent the player from damaging themselves without become invincible?

this is the script that i use to create the damage:

wait(1)
function onTouched(part) 
	local h = part.Parent:findFirstChild("Humanoid") 
	if h~=nil then 
		h.Health = h.Health -2  --Change that number to the ammount of Health you want to decrease
	end 
end 

script.Parent.Touched:connect(onTouched)

video to better explain

1 comment

0

try adding something like if h ~= game.Players.LocalPlayer then

3 answers

✓ Accepted answer

Try using ObjectValues

The only problem I'm seeing is with the script you posted with the question.

You can't find the player, maybe try asking the server script(the one that gets the remote) for the player.

My guess is that one of the clones contain the script, you'll need to add a ObjectValue and set the property "Value" to the player.

wait(1)
local ObjectValue=script.LocalPlayer
local Damage=2
function onTouched(part) 
	local h = part.Parent:findFirstChild("Humanoid") 
	if h~=nil then 
		if game:GetService("Players"):GetPlayerFromCharacter(part.Parent)~=ObjectValue.Value then
			h.Health = h.Health - Damage
		end
	end 
end 

script.Parent.Touched:connect(onTouched)

16 comments

0

Sorry for the text clipping.

0

it isnt from a tool. pressing E summons the ability so yeah

0

?

0

So you're saying, it is from a keybind, if it is a keybind then you get it from a player.

0

it isnt a tool

0

Does it use remotes? If so, can you place links for the scripts

0

Ik it isn't from a tool.

0

Oh yes it does use remotes, ill put the scripts in a pastebin hold on

0

(Sorry if I have bad english)

0

https://ghostbin.com/zELNW / this and the other script are seperate, because i couldnt find a way to implement it all in one script

0

Wait.. Why are there two damage scripts? Do you use the damage script that you placed on the post?

0

yes, the script in the ghostbin basically does this: when it hits a humanoid it deals 20 damage and starts the impact tween. it also makes it so if you hit a wall it starts the impact tween aswell / what i did was i placed the script in the post above inside of the brick thats caused after the explosion / i can provide screenshots to be clearer

0

Please send screenshots

0

Ok I've come up with a solution(The image wasn't loading so I had to read the message you said and I just realized)

0

I'll update my answer

if it is a local script you can:

local plyr = game.Players.LocalPlayer
wait(1)
function onTouched(part) 
    local h = part.Parent:FindFirstChild("Humanoid") 
    if h~=nil then
        if h ~= plyr.Character.Humanoid then
        h.Health = h.Health -2  --Change that number to the ammount of Health you want to decrease
    end 
end
end 

script.Parent.Touched:Connect(onTouched)

If it is a server script then you have to upload all your script

1 comment

0

Its a server script but i tried your code as both local and server and it didnt work

try this script


local lplr = game.Players.LocalPlayer

	function onTouched(part)
	    local h = part.Parent:findFirstChild("Humanoid")
          if h~=nil and h ~= lprl then --if h isnt nil and if h isnt = local player then
	        h.Health = h.Health -2  
	    end
	end
	script.Parent.Touched:connect(onTouched)

1 comment

0

Still damages player :(

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