So basically, I've been making this attack script and I really need this damage thing to work, here's what I got right now, it's meant to work but doesn't. Can anyone please hint out the mistake?
1 | part.Touched:connect( function (hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil then |
3 | if hit.Parent.Name ~ = Player.Name then |
4 | hit.Parent.Humanoid:TakeDamage( math.huge ) |
5 | end |
6 | end |
7 | end ) |
Is this what you meant?
01 | local playername = "tantec" -- name of the player NOT to deal damage to. |
02 |
03 | script.Parent.Touched:Connect( function (hit) |
04 | for i,v in pairs (game.Players:GetPlayers()) do |
05 | if v and v.Character and v.Character:IsAncestorOf(hit) then |
06 | if v.Name:lower() ~ = playername:lower() then |
07 | v.Character:BreakJoints() |
08 | end |
09 | end |
10 | end |
11 | end ) |
part should be defined so maybe put the script under the part and use script.Parent
don't use :connect instead use :Connect
~=nil is also not needed and you shouldn't use hit.Parent~=Player.Name instead, just use if hit.Parent:FindFirstChild("Humanoid") then
math.huge is an infinite value so you can just do max damage or a certain integer hit.Parent.Humanoid.Health = 0
your script should end up like
1 | script.Parent.Touched:Connect( function (hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
3 | hit.Parent:FindFirstChild( "Humanoid" ).Health = 0 |
4 | end |
5 | end ) |