So I'm making a script that changes the player's shirt when they join (and if they don't have a shirt it creates one on them). It prints to 'He has no shirt", but then gives the error "Attempted to index global "S", a nil value.'
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
print("So far so good")
S = character:FindFirstChild("Shirt")
if S then
print("He has a Shirt")
S.ShirtTemplate = ("http://www.roblox.com/asset/?id=137904320")
else
Instance.new("Shirt", character)
print("He has no shirt")
S = character:FindFirstChild("Shirt")
S.ShirtTemplate = ("http://www.roblox.com/asset/?id=137904320")
end
end)
end)

1 comment
I'm sorry, there was a mistake on my end and I posted the wrong stuff in my question (the script I have in there now is the correct script I am actually using). It turns out my real problem was that the Instance.new isn't working, not the CharacterAdded.