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,
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
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.
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