Ad
Log in to vote
0

attempt to index nil with 'Humanoid' error using alvinblox tutorials?

Asked by
xxaxxaz 42
4 months ago
Edited 4 months ago

I was following alvinblox tutorials and this error came up: attempt to index nil with 'Humanoid' can anybody help me?

local serverStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3")

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

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local strength = Instance.new("NumberValue")
    strength.Name = "Strength"
    strength.Parent = leaderstats

    local rebirths = Instance.new("IntValue")
    rebirths.Name = "Rebirths"
    rebirths.Parent = leaderstats

    local dataFolder = Instance.new("Folder")
    dataFolder.Name = player.Name
    dataFolder.Parent = serverStorage.RemoteData

    local debounce = Instance.new("BoolValue")
    debounce.Name = "Debounce"
    debounce.Parent = dataFolder

    local strengthData, rebirthsData

    local success,errormessage = pcall(function()
        strengthData = DataStore:GetAsync("strength-"..player.UserId)
        rebirthsData = DataStore:GetAsync("rebirths-"..player.UserId)
    end)

    if success then
        if strengthData then
            strength.Value = strengthData
            rebirths.Value = rebirthsData
        end
    end

    player.CharacterAppearanceLoaded:Connect(function()
        local humanoid = character.Humanoid--here is the error
        humanoid:WaitForChild("BodyDepthScale").Value = .5 + (strength / 250)
        humanoid:WaitForChild("BodyHeightScale").Value = .5 + (strength.Value / 250)
        humanoid:WaitForChild("BodyWidthScale").Value = .5 + (strength / 250)
        humanoid:WaitForChild("HeadScale").Value = .5 + (strength / 250)
        humanoid.Walkspeed = 16 * (strength.Value / 250)

        strength:GetPropertyChangedSignal("Value"):Connect(function()
            humanoid:WaitForChild("BodyDepthScale").Value = .5 + (strength / 250)
            humanoid:WaitForChild("BodyHeightScale").Value = .5 + (strength.Value / 250)
            humanoid:WaitForChild("BodyWidthScale").Value = .5 + (strength / 250)
            humanoid:WaitForChild("HeadScale").Value = .5 + (strength / 250)
            humanoid.Walkspeed = 16 * (strength.Value / 250)
        end)
    end)

end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        DataStore:SetAsync("strength-"..player.UserId,player.leaderstats.Strength.Value)
        DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
    end)
end)

0
line 41 is error xxaxxaz 42 — 4mo

2 answers

Log in to vote
0
Answered by
MattVSNNL 316 Moderation Voter
4 months ago

You haven't put character at CharacterAppearenceLoaded, Try this

local serverStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3")

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

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local strength = Instance.new("NumberValue")
    strength.Name = "Strength"
    strength.Parent = leaderstats

    local rebirths = Instance.new("IntValue")
    rebirths.Name = "Rebirths"
    rebirths.Parent = leaderstats

    local dataFolder = Instance.new("Folder")
    dataFolder.Name = player.Name
    dataFolder.Parent = serverStorage.RemoteData

    local debounce = Instance.new("BoolValue")
    debounce.Name = "Debounce"
    debounce.Parent = dataFolder

    local strengthData, rebirthsData

    local success,errormessage = pcall(function()
        strengthData = DataStore:GetAsync("strength-"..player.UserId)
        rebirthsData = DataStore:GetAsync("rebirths-"..player.UserId)
    end)

    if success then
        if strengthData then
            strength.Value = strengthData
            rebirths.Value = rebirthsData
        end
    end

    player.CharacterAppearanceLoaded:Connect(function(character)
        local humanoid = character.Humanoid
        humanoid:WaitForChild("BodyDepthScale").Value = .5 + (strength / 250)
        humanoid:WaitForChild("BodyHeightScale").Value = .5 + (strength.Value / 250)
        humanoid:WaitForChild("BodyWidthScale").Value = .5 + (strength / 250)
        humanoid:WaitForChild("HeadScale").Value = .5 + (strength / 250)
        humanoid.Walkspeed = 16 * (strength.Value / 250)

        strength:GetPropertyChangedSignal("Value"):Connect(function()
            humanoid:WaitForChild("BodyDepthScale").Value = .5 + (strength / 250)
            humanoid:WaitForChild("BodyHeightScale").Value = .5 + (strength.Value / 250)
            humanoid:WaitForChild("BodyWidthScale").Value = .5 + (strength / 250)
            humanoid:WaitForChild("HeadScale").Value = .5 + (strength / 250)
            humanoid.Walkspeed = 16 * (strength.Value / 250)
        end)
    end)

end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        DataStore:SetAsync("strength-"..player.UserId,player.leaderstats.Strength.Value)
        DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
    end)
end)

0
thanks for trying but if you has not seen my comment I figured it out but this is basicly the same thing so I will accept answer because it is true. xxaxxaz 42 — 4mo
Ad
Log in to vote
0
Answered by
xxaxxaz 42
4 months ago

nvm I realized what I did do

    player.CharacterAppearanceLoaded:Connect(function()

what I need to do

player.CharacterAppearanceLoaded:Connect(function(character)

I needed to put in word character

0
oh and I allso realized that I forgot to do strength.Value instead of strength xxaxxaz 42 — 4mo

Answer this question