1) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = 0 end end script.Parent.Touched:connect(onTouched)
2) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") end end script.Parent.Touched:connect(onTouched)
3) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = 0 end
This one is more simple, since i assume you are a beginner!
local Part = script.Parent -- Here we are creating a variable, so we can acess the part easier than needing to type script.Parent everytime we need to adjust the part Part.Touched:Connect(function(hit) -- So here is a new thing for you. Events basically fire something when you do something! if hit.Parent:FindFirstChild("Humanoid") then -- Hit is the part that you touch the brick with. And if it contains a humanoid we want to fire something. hit.Parent.Humanoid.Health = 0 -- We are saying the health of the humanoid equals to 0. Remember to have to equal signs if it is in a if statement. end end) -- Self-Explanatory.
Good luck on your scripting progress
This is the working one, the first one
function onTouched(part) -- a function for when a part is touched local h = part.Parent:findFirstChild("Humanoid") -- find a humanoid inside the toucher if h~=nil then -- if the humanoid is not nil then h.Health = 0 -- make the humanoids health 0 end end script.Parent.Touched:connect(onTouched) -- connecting it to the function
This is one way to do it.
script.Parent.Touched:Connect(function(hit) -- if the script.Parent is touched, the function activates if game.Players:GetPlayerFromCharacter(hit.Parent) then -- this makes so it has to be a player, no NPCs local hum = hit.Parent:FindFirstChild("Humanoid") if hum then -- checks to see if it has a humanoid hit.Parent:BreakJoints() -- breaks the joints in the character, killing it end end end