I Just did something like this,
part.Touched:Connect(function(p) if p.Parent.FindFirstChild == ("Humanoid") then local plr = workspace[p.Parent.Name] wait(0.5) plr.Humanoid:TakeDamage(20) wait(0.1) part:Destroy() end end)
end)
but i dont know what did i do wrong can someone help please?
script.Parent.Activated:Connect(function() local character = script.Parent.Parent local Humanoid = character:WaitForChild('Humanoid') local torso = character:WaitForChild('HumanoidRootPart') local part = Instance.new("Part",game.Workspace) part.Size = Vector3.new(7.8, 3.6, 4.2) part.CanCollide = false part.Anchored = true part.CFrame = torso.CFrame+(torso.CFrame.lookVector*3) part.Touched:Connect(function(p) if p.Parent.FindFirstChild == ("Humanoid") then local plr = workspace[p.Parent.Name] wait(0.5) plr.humanoid.Health = plr.humanoid.Health - 20 wait(0.1) part:Destroy() end end) end)
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.
part.Touched:Connect(function(p) if p.Parent.FindFirstChildOfClass("Humanoid") then local plr = workspace[p.Parent.Name] wait(0.5) plr.humanoid.Health = plr.humanoid.Health - 20 wait(0.1) part:Destroy() end end)
part.Touched:Connect(function(p) if p.Parent.FindFirstChild == ("Humanoid") then local plr = workspace[p.Parent.Name] wait(0.5) plr.humanoid.Health = plr.humanoid.Health - 20 wait(0.1) part:Destroy() end end)
this isn't tested but try it atleast.