Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone help with nil player value?

-- 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

✓ Accepted answer

You didn't define player,

local player = game.Players.LocalPlayer

This discussion is preserved as it was. New answers, comments, and votes are closed.