I Just did something like this,
01 | part.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 |
14 | end ) |
end)
but i dont know what did i do wrong can someone help please?
01 | script.Parent.Activated:Connect( function () |
02 |
03 | local character = script.Parent.Parent |
04 | local Humanoid = character:WaitForChild( 'Humanoid' ) |
05 | local torso = character:WaitForChild( 'HumanoidRootPart' ) |
06 |
07 | local part = Instance.new( "Part" ,game.Workspace) |
08 | part.Size = Vector 3. new( 7.8 , 3.6 , 4.2 ) |
09 | part.CanCollide = false |
10 | part.Anchored = true |
11 | part.CFrame = torso.CFrame+(torso.CFrame.lookVector* 3 ) |
12 |
13 | part.Touched:Connect( function (p) |
14 | if p.Parent.FindFirstChild = = ( "Humanoid" ) then |
15 |
Full code is this, other things are working but that part.Touched is broken
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.
01 | part.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 ) |
01 | part.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 |
14 | end ) |
this isn't tested but try it atleast.