I have a basic damage script that does damage to any humanoid. I want to make it deal damage only to the player, meaning any other humanoids such as npcs would not be affected.
script.Parent.Touched:connect(function(hit) pcall(function() hit.Parent.Humanoid:TakeDamage(10) end) end)
I haven't been able to find anything like this, I don't know if it's actually possible. Does anyone have any ideas?
Thanks.
What voidofdeathfire said was right and works, but there is a better way than using a generic for loop.
script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:WaitForChild("Humanoid", 3) local Damg = 20 local debounce = true if humanoid and debounce then local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) if Player.Name == hit.Parent.Name then humanoid:TakeDamage(Damg) debounce = false end end wait(1) debounce = true end)
Look if the players name matches with the Humanoid's name
script.Parent.Touched:connect(function(hit) for i,v in pairs(game.Players:GetChildren())do local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid ~= nil then if humanoid.Parent.Name == v.name then humanoid:TakeDamage(10) end end end end)
if you have any problems please comment