Hi, so I'm a bit new to Programming and just dived into Roblox. The goal I'm trying to accomplish here is making a script for a part in which will insta-kill any roblox player that steps on it.
Here is my code:
local Part = script.Parent
function local onTouch(hit)
human = hit.Parent:FindFirstChild("Humanoid") -- Finds the "Humanoid" part
if h ~= nil then
human.Health = 0
end
end
if Part.Touched then -- If something is touching the part
onTouch(Part.Touched) -- Invokes the "onTouch" function with the character's leg being it's parameter
end
I've written down an explanation (or what I think it means at least). However it does not work, I also tried putting an infinite while loop on the if statement but that just crashes the game. If someone can spot the error to my code or suggest me a new form of code I would really appreciate it.
I would also like to note, that I'm currently a noob, so an explanation on each line would help and why you chose this etc etc. Thank you very much

5 comments
You could also do:
while wait() do endAlso, if you were checking for something, 'repeat wait() until'
I have a question, wouldn't the line "script.Parent.Touched:connect(onTouch)" require a loop to constantly check it?
I also found that removing the if statement works as well, but creates more lag.
Touched is one more of an event, not a property. This means anytime anything touches the brick, the event will fire. The event requires a function to process any code, with the Touched event it will provide a brick that touched it. If you're just waiting for an event to happen, you could do game.Workspace.Part.Touched:Wait() and it will wait until part in workspace is touched.