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

Hit touched event hitting own Player?

Asked by
Aozwel 71
3 years ago

Hey there,

I’ve got a quick question I’ve currently got a Sword that does damage based on

 if hit.Parent:FindFirstChild(“Humanoid”)

however its also of course taking into account my own Humanoid therefore inflicting damage onto myself, How would i go about making a check if the Hit is not the Player themselves

Thanks,

3 answers

Log in to vote
1
Answered by
iiAceMo 50
3 years ago

this is my first time answering a question but try this:

local tool = script.Parent -- change this if needed

if hit.Parent:FindFirstChild("Humanoid") then
    if hit.Parent.Name ~= tool.Parent.Name then
        -- ur script here
    end
end

not sure if this will work but try it out

Ad
Log in to vote
0
Answered by 3 years ago

Try this:

game.Players.PlayerAdded:Connect(function(player)
if hit.Parent:FindFirstChild(“Name”) ~= player.Name then
if hit.Parent:FindFirstChild(“Humanoid”) then

The basic premise here is that the game checks if what’s being hit is you (I use players.playeradded since it’s like the equivalent to localplayer in a server script). Then, the game just does the sword thing. If this doesn’t work let me know.

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Hi, you would rename it to players instead of player or humanoid. That just says you and not everyone else. So it should be something like this:

local Players = game:GetService("Players") --- Gets players

if hit.Parent:FindFirstChild(“Players”) -- If you hit the players then do damage

Also the API has information about this at: https://developer.roblox.com/en-us/api-reference/class/Players

Answer this question