Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Touched function not getting the humanoid?

Asked by 4 years ago
local potion = script.Parent
local character
potion.Handle.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("HumanoidRootPart") then
        potion.Parent = hit.Parent
        for i,v in pairs(potion:GetChildren()) do
            if v:IsA("Part") or v:IsA("UnionOperation") then
                v.Anchored = false
                v.CanCollide = false
                character = hit.Parent
            end
        end
    end
end)

local humanoid

while wait() do
    if character:FindFirstChild("Humanoid") then
        humanoid = character.Humanoid
        break
    end
end
potion.Activated:Connect(function()
    if humanoid then
        if humanoid.Health <= 99 then
            local info = TweenInfo.new(1)
            local tween = game:GetService("TweenService"):Create(humanoid,info,{Health = 100})
            tween:Play()
            potion:Destroy()
        end
    end
end)

I made a health potion script. It's not getting the humanoid touched, therefore the character is still nil? The activated function works all right. What's the issue here?

0
I fixed it. AcrylixDev 119 — 4y
0
I fixed it. AcrylixDev 119 — 4y

Answer this question