Scripting Help with Shirt ID's

I want to make it so where the shirt on the model is the exact same shirt of the Player, and it works for all players, so it is different for all players, and it shows their Shirt

20:16:26.974 - Workspace.ShirtRack.Shirt.Script:1: attempt to index field ‘LocalPlayer’ (a nil value)

I tried going on developer discords, but no one wanted to help.

Thank you for reading and responding!

local PlayersShirtTemplate = game.Players.LocalPlayer.Character.Shirt.ShirtTemplate

script.Parent.Parent.Shirt.ShirtTemplate = PlayersShirtTemplate
1 Like

Keep in mind that LocalPlayer is only accessible from a LocalScript, and you may have to yield for the character and their appearance.

What is this for exactly? You could also use a remote to fire the shirt id into the model.

@ProjectExtraction And how would I do that?

Only LocalScripts can access the LocalPlayer. Since this is a server script, you have to get the player object, perhaps using a touched event, such as

local players = game:GetService("Players")

local function touched(object)
    local character = players:GetPlayerFromCharacter(object.Parent)
    if character then
        --It's the player
        shirt.ShirtTemplate = character.Shirt.ShirtTemplate
    end
end

workspace.Part.Touched:Connect(touched)

Or you could get the player through a player join function.

@KingOfHungry It didn’t work.

21:48:10.052 - Shirt is not a valid member of Player

If you want each player to see their own shirt on there, just transfer this to a local script, move it to something that runs scripts locally (such as PlayerGui) and reference the NPC’s character through game.Workspace instead of script.Parent.

Still gives me the same error, changed the variables and stuff, put it in StarterGui as a script but still doesn’t work.

Put it as a localscript, not a script.

Still gives me the same error.

It shouldn’t, mind including a new screenshot of the output as well as a screenshot of where the script is located and a screenshot of the code itself?

https://gyazo.com/98e63405a5371f4f07353fd1c7bb4548

That’s a different error and that is occurring because you need to get the shirt from the Players character, not the player itself.

1 Like

So how would I do that? @RudraVII

Shirt isn’t part of the player object. You can get the player’s character via Player.Character.

1 Like

Alright, I appreciate it thank you.

1 Like