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

Why won't my humanoid get healed?

Asked by 10 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
wait(2)
game.Players.LocalPlayer.PlayerGui.HarvestGui.Frame.Visible = false

 end

 script.Parent.ClickDetector.MouseClick:connect(onClicked)

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?

~Minikitkat

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 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
            end
        end
        child.Humanoid.Health = 0
        child.Name = "LittleSister (Harvested)"
        plr.PlayerGui.HarvestGui.Frame.Visible = true
        wait(2)
        plr.PlayerGui.HarvestGui.Frame.Visible = false
    end
end)

This should be a server script

0
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 — 10y
0
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 8144 — 10y
Ad

Answer this question