New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

Why won't my humanoid get healed?

Asked by 5 years ago

Hello! I am making a "Little sister" Form bioshock in which when clicked, it will heal you! I think when I use the function: function onClicked(click) That makes the click part of it usable in a script like it is below. I'm not sure what to call that.

function onClicked(click)
    local human = click.Parent:findFirstChild("Humanoid")
        human.Health = 100
        --Below is fine, above is not--
child = script.Parent.Parent
child.Head.Anchored = false
child:FindFirstChild("Left Arm").Anchored = false
child:FindFirstChild("Left Leg").Anchored = false
child.Part.Anchored = false
child:FindFirstChild("Right Arm").Anchored = false
child:FindFirstChild("Right Leg").Anchored = false
child.Torso.Anchored = false
child.Humanoid.Health = 0
child.Name = "LittleSister (Harvested)"
game.Players.LocalPlayer.PlayerGui.HarvestGui.Frame.Visible = true
game.Players.LocalPlayer.PlayerGui.HarvestGui.Frame.Visible = false



The problem is the 'human' part is not found. here is the output: 13:26:50.992 - Workspace.Sister_Vent.LittleSister.Torso.Script:3: attempt to index local 'human' (a nil value) 13:26:50.993 - Stack Begin 13:26:50.994 - Script 'Workspace.Sister_Vent.LittleSister.Torso.Script', Line 3 Any help?


1 answer

Log in to vote
Answered by
Goulstem 8072 Badge of Merit Moderation Voter Administrator Community Moderator
5 years ago

The problem here is that the Clicked Event returns the player who clicked, not the Character.

To fix this..

function onClicked(plr)
    if plr and plr.Character then
        plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth
        local child = script.Parent.Parent
        for i,v in pairs(child:GetChildren()) do
            if v:IsA('BasePart') then
                v.Anchored = false
        child.Humanoid.Health = 0
        child.Name = "LittleSister (Harvested)"
        plr.PlayerGui.HarvestGui.Frame.Visible = true
        plr.PlayerGui.HarvestGui.Frame.Visible = false

This should be a server script

Thanks! This worked! I had to modify it though. All I needed was the health part I just thought it would be better to see the whole script. Thanks! minikitkat 687 — 5y
I just modified the part where you unanchor all the limbs, what I posted should work but if it didn't then sorry. Have fun coding(: Goulstem 8072 — 5y

Answer this question