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
7 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?

1part.Touched:connect(function(hit)
2if hit.Parent:FindFirstChild("Humanoid") ~= nil then
3if hit.Parent.Name ~= Player.Name then
4hit.Parent.Humanoid:TakeDamage(math.huge)
5end
6end
7end)

2 answers

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

Is this what you meant?

01local playername = "tantec" -- name of the player NOT to deal damage to.
02 
03script.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
11end)
Ad
Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
7 years ago
Edited 7 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

1script.Parent.Touched:Connect(function(hit)
2if hit.Parent:FindFirstChild("Humanoid") then
3hit.Parent:FindFirstChild("Humanoid").Health = 0
4end
5end)
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 — 7y
0
None. One's deprecated. Not really an issue. OldPalHappy 1477 — 7y
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 — 7y

Answer this question