So...in my script what I have is a model with several parts and a script. This script is suppose to make it so that if any of these parts gets hit, then the following function will occur. The output error I am getting is as follows...
23:06:43.724 - Touched is not a valid member of Script 23:06:43.724 - Script 'Workspace.Model.Script', Line 21 23:06:43.724 - Stack End
Here is the script...
for i, child in pairs (script.Parent:GetChildren()) do
if child:IsA("BasePart") then -- consider only the Parts of the model
function onTouch(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
while (human ~= nil) do
local s = wait(1)
local health = human.Health
if health > 0 and health < human.MaxHealth then
local newHealthDelta = 0.01 * s * human.MaxHealth
health = health + newHealthDelta
human.Health = math.min(health,human.MaxHealth)
end
end
if human.Health > human.MaxHealth then
human.Health = human.MaxHealth
end
end
end
end
connection = child.Touched:connect(onTouch)
end
