Having a small problem, probably with an easy fix. How do I find PlrName in workspace in order to edit pants. plrname is not a valid member of Workspace
game.Players.PlayerAdded:connect(function(player) local plrname = player.Name workspace.plrname.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=18103438" end)
Thanks :) Sorry if it's ridiculously easy. lol
When you say something like game.Workspace
, that is sugar for game["Workspace"]
.
In other words, .
is just table-access. And you could, instead of writing game.Workspace
write something like
local n = "Workspace" local w = game[n]
In this case, you could use workspace[player.Name]
to find the thing in the workspace with the same name as player
.
However, you'll get an error if the object doesn't exist. If you aren't sure that it will exist, you should be using workspace:FindFirstChild(player.Name)
.
However -- this is NOT how you should be doing this. Player objects have a .Character
property which gives you their Character model.
They also have a .CharacterAdded
event which will give you their character each time they respawn. Use those.
You normally never need to inspect ROBLOX objects based on their name. You almost always should just keep the thing itself and use its properties, instead of getting a piece of the information and then doing your own search.
You can't search Workspace for a string. You have to search for the name of an object. player.Name
is a string, so it won't work. There's a much easier way to get to the Character anyway. Just do this:
game.Players.PlayerAdded:connect(function(player) player.Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=18103438" end)
I just said player.Character
because there's a character value inside the actual player object that leads to the player's character
Nice shirt, btw :P