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

"Attempt to index local 'Pants4' (a nil value)"?

Asked by 8 years ago
wait(2)
game.Players.PlayerAdded:connect(function(Player)
local stats = Instance.new("IntValue", Player)
stats.Name = "stats"
local Hat = Instance.new("NumberValue", stats)
Hat.Name = "Hat"
local Shirt = Instance.new("NumberValue", stats)
Shirt.Name = "Shirt"
local Pants = Instance.new("NumberValue", stats)
Pants.Name = "Pants"
wait(2)
Hat.Value = math.random(1,5)
wait(0.1)
Shirt.Value = math.random(1,5)
wait(0.1)
Pants.Value = math.random(1,4)
wait(0.1)
print("This worked")

if Hat.Value == 1 then
    local Hat1 = game.ServerStorage.Hair:findFirstChild("Hair1")
    local Hat1Clone = Hat1:clone()
    Hat1Clone.Parent = Player
elseif Hat.Value == 2 then
    local Hat2 = game.ServerStorage.Hair:findFirstChild("Hair2")
    local Hair2Clone = Hat2:clone()
    Hair2Clone.Parent = Player
elseif Hat.Value == 3 then
    local Hat3 = game.ServerStorage.Hair:findFirstChild("Hair3")
    local Hair3Clone = Hat3:clone()
    Hair3Clone.Parent = Player
elseif Hat.Value == 4 then
    local Hat4 = game.ServerStorage.Hair:findFirstChild("Hair4")
    local Hair4Clone = Hat4:clone()
    Hair4Clone.Parent = Player
elseif Hat.Value == 5 then
    local Hat5 = game.ServerStorage.Hair:findFirstChild("Hair5")
    local Hair5Clone = Hat5:clone()
    Hair5Clone.Parent = Player
end

if Shirt.Value == 1 then
    local Shirt1 = game.ServerStorage.Shirt:findFirstChild("Shirt1")
    local Shirt1Clone = Shirt1:clone()
    Shirt1Clone.Parent = Player
elseif Shirt.Value == 2 then
    local Shirt2 = game.ServerStorage.Shirt:findFirstChild("Shirt2")
    local Shirt2Clone = Shirt2:clone()
    Shirt2Clone.Parent = Player
elseif Shirt.Value == 3 then
    local Shirt3 = game.ServerStorage.Shirt:findFirstChild("Shirt3")
    local Shirt3Clone = Shirt3:clone()
    Shirt3Clone.Parent = Player
elseif Shirt.Value == 4 then
    local Shirt4 = game.ServerStorage.Shirt:findFirstChild("Shirt4")
    local Shirt4Clone = Shirt4:clone()
    Shirt4Clone.Parent = Player
elseif Shirt.Value == 5 then
    local Shirt5 = game.ServerStorage.Shirt:findFirstChild("Shirt5")
    local Shirt5Clone = Shirt5:clone()
    Shirt5Clone.Parent = Player
end 

if Pants.Value == 1 then
    local Pants1 = game.ServerStorage.Shirt:findFirstChild("Pants1")
    local Pants1Clone = Pants1:clone()
    Pants1Clone.Parent = Player
elseif Pants.Value == 2 then
    local Pants2 = game.ServerStorage.Shirt:findFirstChild("Pants2")
    local Pants2Clone = Pants2:clone()
    Pants2Clone.Parent = Player
elseif Pants.Value == 3 then
    local Pants3 = game.ServerStorage.Shirt:findFirstChild("Pants3")
    local Pants3Clone = Pants3:clone()
    Pants3Clone.Parent = Player
elseif Pants.Value == 4 then
    local Pants4 = game.ServerStorage.Shirt:findFirstChild("Pants4")
    local Pants4Clone = Pants4:clone()
    Pants4Clone.Parent = Player
end

end)

1 answer

Log in to vote
1
Answered by 8 years ago

It is attempting to access Pants4 on line 77. There is no definite answer for this, go back and check your hierarchy and make sure game.ServerStorage.Shirt.Pants4 exists. If that is existing, see if anything else is moving Pants4 to another location of deleting it.

Better questions next time please: https://scriptinghelpers.org/help/how-post-good-questions-answers

Ad

Answer this question