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

Character Parts Are Returning As Nil?

Asked by
Donut792 216 Moderation Voter
4 years ago

alright so where it does a :GetChildren() on the players character it returns nil for each value in the table i am unsure how to fix tihs Script:

script.Parent.Lift.OnServerEvent:Connect(function(Player)
    local list = {"Head","LeftFoot","LeftHand","LeftLowerArm","LeftUpperArm","LeftLowerLeg","LeftUpperLeg","LowerTorso","RightFoot","RightHand","RightLowerArm","RightLowerLeg","RightUpperArm","RightUpperLeg","UpperTorso","HumanoidRootPart"}
    Player.leaderstats.Strength.Value = Player.leaderstats.Strength.Value + 1
    Player.Character.Humanoid.WalkSpeed = 0
    Player.Character.Humanoid.JumpPower = 0
      for i = 1, #list do
        local parts = Player.Character:GetChildren()
        print(parts.Name)
           if parts.ClassName == "Part" or parts.ClassName == "MeshPart" and parts.Name == list[i] then
    parts.Size = parts.Size + parts.Size/200
    print("sized")
    end
end
    wait(.5)
    Player.Character.Humanoid.WalkSpeed = 16
    Player.Character.Humanoid.JumpPower = 50
end)
0
Wow Ankur_007 290 — 4y

1 answer

Log in to vote
1
Answered by
le145 20
4 years ago

I think i have fixed your problem, first I removed the first table becuase, it was not needed at all. Second, I made a remote event called Lift and let it in ReplicatedStorage moving the script to ServerScriptService.

The for loop was receiving the info from the first list so you were declaring :GetChildren() more times than needed, also :GetChildren() returns a table so you cannot just do part:GetChildren().Name, you first need to make a for look and then print the name of each table values

Im not sure but I think Player.Character:GetChildren() Was returning nil cause as .Character simulates the character it is not getting the real info from the real one. So what I did was a

workspace:FindFirstChild(Player.Name)

doing that and then using :GetChildren() worked

Also .ClassName() i dont think its used I mostly use :IsA() but btw here the fix

game.ReplicatedStorage.Lift.OnServerEvent:Connect(function(Player)
    --local list = {"Head","LeftFoot","LeftHand","LeftLowerArm","LeftUpperArm","LeftLowerLeg","LeftUpperLeg","LowerTorso","RightFoot","RightHand","RightLowerArm","RightLowerLeg","RightUpperArm","RightUpperLeg","UpperTorso","HumanoidRootPart"}
    Player.leaderstats.Strength.Value = Player.leaderstats.Strength.Value + 1
    Player.Character.Humanoid.WalkSpeed = 0
    Player.Character.Humanoid.JumpPower = 0
    ----Modified by le145
    local PlayerWork = workspace:FindFirstChild(Player.Name)
    local allParts = PlayerWork:GetChildren()
    for i,v in pairs(allParts)do
        if v:IsA("MeshPart") then
            v.Size = v.Size+v.Size/200
        elseif v.Name == "Head" then
            v.Mesh.Scale = v.Mesh.Scale+v.Mesh.Scale/200
        elseif v:IsA("Accessory")then
            local mes = v.Handle
            if mes then
                local hand = mes:FindFirstChild("SpecialMesh") or mes:FindFirstChild("Mesh")
                hand.Scale = hand.Scale+hand.Scale/200
            end
        end
    end
    ----------------------------------
    wait(.5)
    Player.Character.Humanoid.WalkSpeed = 16
    Player.Character.Humanoid.JumpPower = 50
end)
0
thanks i got the issue solved just about the same way you did here i just forgot to get back on the site Donut792 216 — 4y
Ad

Answer this question