Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help With Script errors?

I'm not sure if this is the right way to do it. This is supposed to heal a person by standing in it, but it does not work. It says line 8 is the error for not knowing what "hitzr" is.

while script.Parent.Touched do
	wait(.2)
	script.Parent.Touched:connect(function(hit)
		hitzr = hit
	end)
	if hitzr.Parent:FindFirstChild("Humanoid") then
		hitzr.Parent:FindFirstChild("Humanoid").Health = hitzr.Parent:FindFirstChild("Humanoid").Health + 25
	end
end

1 answer

Touched is an event. Events are a class with a connection method that fires when the event is triggered. What an event is not is a condition. An event exists.

If what you mean to check is that the part is currently being touched, then start the loop when it is touched and end it when TouchEnded is fired.

hitzr is not defined. On line 4 it is defined only when script.Parent is touched, but since it hasn't been touched between the time the connection was created and the time the line immediately following the creation of the connection is executed, it still is not defined. Check to make sure it exists first.

This discussion is preserved as it was. New answers, comments, and votes are closed.