I have an error on my healing item? Anyone got opinions on how to fix it?
My script:
local MAX_HEALTH = 100
local ENABLED_TRANSPARENCY = 0.4
local DISABLED_TRANSPARENCY = 0.9
local COOLDOWN = 20
local healthPickupsFolder = workspace:WaitForChild("HealthPickups") -- Variable for the folder.
local healthPickups = healthPickupsFolder:GetChildren() -- Variable for healthPickups
local function onTouchHealthPickup(otherPart, healthPickup) -- Function that checks that a object that touched is a character and haves a humanoid.
local character = otherPart.Parent -- Variable for character.
local humanoid = character:FindFirstChildWhichIsA("Humanoid") -- Humanoid Variable.
if humanoid then -- If the object has a humanoid inside it, it will put the humanoid's health to the MAX_Health Varible.
humanoid.Health = MAX_HEALTH
healthPickup.Transparency = DISABLED_TRANSPARENCY
healthPickup:SetAttribute("Enabled", false)
wait(COOLDOWN)
healthPickup.Transparency = ENABLED_TRANSPARENCY
healthPickup:SetAttribute("Enabled", true)
end
end
for _, healthPickup in ipairs(healthPickups) do -- Call the onTouchHealthPickups function, passing both the otherPart parameter and the healthPickup.
healthPickup.Touched:Connect(function(otherPart)
onTouch
HealthPickup(otherPart, healthPickup)
end)