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

Can someone help with nil player value?

Asked by
Akozta 40
8 years ago
-- First lets remove the old hats!
for i,v in pairs(player:GetChildren()) do -- Lets get the Player's Characters Children!
    if v:IsA("Hat") then -- Beep beep beep, we found one!
        ypcall(function() -- Why not have some protection?
            v:Destroy() -- Boom, hat is gone!
        end) -- end for ypcall
    end -- end for if statement
end -- end for searching Characters children

-- Now we need the hats you want to give to the player!
local AssetIds = {1365696,1365693} -- Put the hat asset ids into here, I put two example ids in
for i,v in pairs(AssetIds) do -- Going through table
    game:GetService("InsertService"):LoadAsset(v):GetChildren()[1].Parent = player -- Inserting hat and parenting to Players character
end -- End for going through AssetIds table

It is supposed to let you remove your old hat and get a new one once the gui is click but the output says. Players.Player.PlayerGui.NewClothesGui.MorphButton.Hat script:2: attempt to index global 'player' (a nil value)

1 answer

Log in to vote
1
Answered by 8 years ago

You didn't define player,

local player = game.Players.LocalPlayer
Ad

Answer this question