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

Part touched connect function (???)

Asked by 5 years ago
Edited 5 years ago

I Just did something like this,

01part.Touched:Connect(function(p)
02    if p.Parent.FindFirstChild == ("Humanoid") then
03 
04        local plr = workspace[p.Parent.Name]
05 
06        wait(0.5)
07            plr.Humanoid:TakeDamage(20)
08        wait(0.1)
09        part:Destroy()
10 
11 
12    end
13 
14end)

end)

but i dont know what did i do wrong can someone help please?

01script.Parent.Activated:Connect(function()
02 
03local character = script.Parent.Parent
04local Humanoid = character:WaitForChild('Humanoid')
05local torso = character:WaitForChild('HumanoidRootPart')
06 
07local part = Instance.new("Part",game.Workspace)
08part.Size = Vector3.new(7.8, 3.6, 4.2)
09part.CanCollide = false
10part.Anchored = true
11part.CFrame = torso.CFrame+(torso.CFrame.lookVector*3)
12 
13part.Touched:Connect(function(p)
14    if p.Parent.FindFirstChild == ("Humanoid") then
15 
View all 28 lines...

Full code is this, other things are working but that part.Touched is broken

2 answers

Log in to vote
0
Answered by 5 years ago

Easy mistake, FindFirstChild = ("Humanoid") doesn't work because you are asking to find the first child and equalizing it with "Humanoid"

Just copy this code, and you'll be on your way.

I also recommend using "FindFirstChildOfClass" for the best humanoid detection, but remove that if you don't want it.

01part.Touched:Connect(function(p)
02        if p.Parent.FindFirstChildOfClass("Humanoid") then
03 
04            local plr = workspace[p.Parent.Name]
05 
06            wait(0.5)
07                plr.humanoid.Health = plr.humanoid.Health - 20
08            wait(0.1)
09            part:Destroy()
10 
11        end 
12    end)
0
Its worked but its killing instantly, i want do to once 20 when u Activated the tool aSpecialGuy 18 — 5y
0
And the part is killing me too i just want to kill custom models like zombies and not players. Should i change Humanoid name or something what i have to do for it ? aSpecialGuy 18 — 5y
0
Sorry, I am late. You should just make sure that it doesn't kill Players TheJellyNinja_XD13 62 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
01part.Touched:Connect(function(p)
02    if p.Parent.FindFirstChild == ("Humanoid") then
03 
04        local plr = workspace[p.Parent.Name]
05 
06        wait(0.5)
07            plr.humanoid.Health = plr.humanoid.Health - 20
08        wait(0.1)
09        part:Destroy()
10 
11 
12    end
13 
14end)

this isn't tested but try it atleast.

Answer this question