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

.Touched function doesn't work for me when I'm trying to deal damage to others, help?

Asked by
tantec 305 Moderation Voter
6 years ago

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?

part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
if hit.Parent.Name ~= Player.Name then
hit.Parent.Humanoid:TakeDamage(math.huge)
end
end
end)

2 answers

Log in to vote
1
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

Is this what you meant?

local playername = "tantec" -- name of the player NOT to deal damage to.

script.Parent.Touched:Connect(function(hit)
    for i,v in pairs(game.Players:GetPlayers())do
        if v and v.Character and v.Character:IsAncestorOf(hit) then
            if v.Name:lower() ~= playername:lower() then
                v.Character:BreakJoints()
            end
        end
    end
end)
Ad
Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago
Edited 6 years ago

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

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid").Health = 0
end
end)
0
I don't get it. Why do people keep complaining about using :connect or :Connect? It's a RBXSignal, what diffirences are there between those two? magicguy78942 238 — 6y
0
None. One's deprecated. Not really an issue. OldPalHappy 1477 — 6y
0
I don't think I've rephrased this properly, basically the original script was meant to kill others and not myself, plus the script that I'm using is for script builder so I can't do it like that. Also, the script works on a part that's not touching me so I think the problem is that it's only getting my name and no one else because it spawns from me tantec 305 — 6y

Answer this question