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

Is this right for a killbrick script?

Asked by 8 years ago
function ontouched (hit)

Local h= findfirstchild = (humanoid)

If h~=nill then

Humanoid health = 0

End
End


script.parent.touched:connect (ontouched)

2 answers

Log in to vote
2
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

Good try. I admire your effort, but here are some tips.

You should set up your function like this if you are only going to use the function once in your script. For cleaner and more compacted coding:

script.Parent.Touched:connect(function(Part)

end)

Coding in every language is case sensitive. So be aware of that, in ROBLOX Studio it should underline the syntax errors you have. In this case local, if and end needs to be all lowercase. To define h and check for h, it's more efficient to just put if h then. if not Part.Parent then return end is for safety measures.

script.Parent.Touched:connect(function(Part)
if not Part.Parent then return end
local h = Part.Parent:FindFirstChild('Humanoid')
if not h then return end
h.Health = 0
end)
Ad
Log in to vote
0
Answered by
Qu_xtty -8
4 years ago

function onTouched(Obj) local h = Obj.Parent:FindFirstChild("Humanoid") if h then h.Health = 0 end end

script.Parent.Touched:Connect(onTouched)

Answer this question