I'm trying to make one of those barista uniform things for a client and this seems to only work in studio:
local b = script.Parent
local plr = b.Parent.Parent.Parent.Parent
plr.CharacterAdded:wait()
local char = plr.Character
local shirtID = 169511223
local pantID = 0
b.MouseButton1Click:connect(function()
if char:FindFirstChild("Shirt") then
local v = char:FindFirstChild("Shirt")
v.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtID
else
local s = Instance.new("Shirt", char)
s.ShirtTemplate = "http://www.roblox.com/asset/?id="..shirtID
s.Name = "Shirt"
end
end)
b.MouseButton1Click:connect(function()
if char:FindFirstChild("Pants") then
local v = char:FindFirstChild("Pants")
v.PantsTemplate = "http://www.roblox.com/asset/?id="..pantID
else
local s = Instance.new("Pants", char)
s.PantsTemplate = "http://www.roblox.com/asset/?id="..pantID
s.Name = "Pants"
end
end)
I do not know why

10 comments
Sometimes that script will run before the player loads, so add
WaitForChild.where?
Your Variables of course.
@TheContinentofEurope You may want to explain which Variables exactly; He could misinterpret what you mean, and type for the Variables (for example, line 2) as 'b:WaitforChild("Parent"):WaitForChild("Parent"):WaitForChild("Parent")' and so on (and may do it with the Player's Character as well. Just a bit of a heads up. :P
The character is already being waited for with plr.CharacterAdded:wait() if that's where you want me to put it.
@Hyphonated What isn't working exactly about the code? What is not working in Online mode for it? Where isn't it doing it's job (or purpose, in other words)? These Questions (information) are important so that we can give you a legitimate Answer, and so we can prepare to Answer your Question with high hopes. :)
There are no errors, that's why I'm here. I don't know where it's not doing it's job. It works in studio but not online.
Add a wait(1) before the first line. The client scripts sometimes will load and run before the player object is initially created initially as TheContinentofEurope explained.
even then it does not work
If there is no errors, it usually means the script is yielding. You may want to check your parenting on line 2 or add a repeat loop to yield until the variable plr is a player.