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

How do I call the player's Humanoid?

Asked by 3 years ago

I would like the player's max health value to be 300 times their health stat value, but I'm unsure how to call the humanoid in my scripts. Both scripts are regular scripts Stats script:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        -- Level

        local level = Instance.new("IntValue")
        level.Name = "Level"
        level.Value = 0
        level.Parent = player

        --Stats
        local strengthvalue = Instance.new("IntValue", char)
        strengthvalue.Name = "Combat"
        strengthvalue.Value = 1
        strengthvalue.Parent = player

        local healthvalue = Instance.new("IntValue", char)
        healthvalue.Name = "Endurance"
        healthvalue.Value = 1
        healthvalue.Parent = player

        local staminavalue = Instance.new("IntValue", char)
        staminavalue.Name = "Fortitude"
        staminavalue.Value = 1
        staminavalue.Parent = player

        local modevalue = Instance.new("IntValue", char)
        modevalue.Name = "Energy"
        modevalue.Value = 1
        modevalue.Parent = player

        --Balance and Avail Stats

        local bal = Instance.new("IntValue")
        bal.Name = "Balance"
        bal.Value = 0
        bal.Parent = player

        local availstats = Instance.new("IntValue", char)
        availstats.Name = "AvailableStats"
        availstats.Value = 0
        availstats.Parent = player
       end)
end)

Max Health script:

game.Workspace:WaitForChild("Character").Humanoid.MaxHealth = 300 * game.Players.LocalPlayer.Endurance.Value
0
You can't have Local player in a regular script. How about you just combine both script so you can reference the player. gamingwithjbthepro 76 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You can't have Local player in a regular script.

also you are telling the int value to parent it to the character but immediately change it to player just so you know character is the player on workspace the player inside Players is the one handling the Gui, local scripts, stats and some other stuff.

you don't have to separate this two script you can combine them too.

game.Players.PlayerAdded:Connect(function(player)
        -- Level

        local level = Instance.new("IntValue",player) -- the object after the comma is going to be its parent so no need to call level.Parent = player
        level.Name = "Level"
        level.Value = 0

        --Stats
        local strengthvalue = Instance.new("IntValue", player)
        strengthvalue.Name = "Combat"
        strengthvalue.Value = 1

        local healthvalue = Instance.new("IntValue", player)
        healthvalue.Name = "Endurance"
        healthvalue.Value = 1

        local staminavalue = Instance.new("IntValue", player)
        staminavalue.Name = "Fortitude"
        staminavalue.Value = 1

        local modevalue = Instance.new("IntValue", player)
        modevalue.Name = "Energy"
        modevalue.Value = 1

        --Balance and Avail Stats

        local bal = Instance.new("IntValue",player)
        bal.Name = "Balance"
        bal.Value = 0

        local availstats = Instance.new("IntValue", player)
        availstats.Name = "AvailableStats"
        availstats.Value = 0

      player.CharacterAdded:Connect(function(char) -- a function that let's you know if the the character of a player has been added to the workspace
        local hum = char:FindFirstChild("Humanoid") 
        if hum ~= nil then -- checking if humanoid is not nil
            hum.MaxHealth *= 300 -- this is just the same as calling it like this hum.MaxHealth = hum.MaxHealth * 300

        end
    end)
end)
0
That simplifies it a lot more, thanks a lot I appreciate it! IcyMustard 4 — 3y
Ad

Answer this question