This script isn't working, it says attempt to call a nil value but not killing.
function onTouched (part)
local h = part.Parent:findFirstChild("Humanoid")
if(h~=nil)then
h.Health = 0
end
end
This script isn't working, it says attempt to call a nil value but not killing.
function onTouched (part)
local h = part.Parent:findFirstChild("Humanoid")
if(h~=nil)then
h.Health = 0
end
end
You are getting there but I can see your Mistake, There is no (connection line) to it, this is what I mean:
function onTouched (part)
local h = part.Parent:findFirstChild("Humanoid")
if(h~=nil)then
h.Health = 0
end
end
script.Parent.Touched:connect(onTouched)
Thx I can't believe i missed this lol
This is what I thought, but not having a connection line is unrelated to the error message.
after I've been Hacked, I've lost 2 Reps.
A connection line is not an end, you should probably edit your answer.
sorry.
Your problem is that you never connected the function to an event.
To do so then you need to write something called a 'connection line'. Connection lines can either be in the definition of the function or outside. When they're inside, then it's called an Anonymous function
Connection line example; --NOTE: This would only work if the thing you want to touch is the script's parent
function onTouched (part)
local h = part.Parent:FindFirstChild("Humanoid")
if h then
h.Health = 0
end
end
--[[ This is the connection statement, you tie the wanted function into the wanted event by placing the function name inside of the parenthasi]]
script.Parent.Touched:connect(onTouched)
Anonymous function example; --NOTE: This would only work if the thing you want to touch is the script's parent
--[[With anonymous functions, you define the function INSIDE the connection statement, and you don't name the function]]
script.Parent.Touched:connect(function(part)
local h = part.Parent:FindFirstChild('Humanoid')
if h then
h.Health = 0
end
end) --Remember to place the parenthasi there to end the connection
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
Do you have an event connection line?
If my answer helped please Accept answer and Upvote please.
A connection line has nothing to do with the error. If the connection line's wrong, then the function itself will not run. On line 3, "~=nil" is redundant. Mind as well put it as "if h then".
^