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

Making Sure Player has Clothes?

--------------------------------------------------------------------
Character.Pants.PantsTemplate = "http://www.roblox.com/asset/?id=(ID)"
-----------------------------------------------------------------------------

Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=(ID)" if Character.Shirt == nil then
	Instance.new("Shirt").Parent = Character
	wait()
	Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=(ID)"
end

Character["Shirt Graphic"].Graphic = "http://www.roblox.com/asset/?id=(ID)" if Character["Shirt Graphic"] == nil then
	Instance.new("ShirtGraphic").Parent = Character
	wait()
	Character["Shirt Graphic"].Graphic = "http://www.roblox.com/asset/?id=(ID)"
end

When I run this script, and the Shirt Graphic is equal to nil, it doesn't run the command told to if it is nil, in the console it just tells me "Attempt to index nil value"

I did add Template IDs into (ID) sections. Earlier in the script it told the script what Character is equal to

1 comment

0

Oh, and I did add template IDs to the (ID) parts

1 answer

✓ Accepted answer

Line 11 tries to set the shirt graphic's graphics and will error if there is no shirt graphic since you can't set the graphics value of nothing.

Character.Pants.PantsTemplate = "http://www.roblox.com/asset/?id=(ID)"

Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=(ID)" if Character.Shirt == nil then
    Instance.new("Shirt").Parent = Character
    wait()
    Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=(ID)"
end

if Character["Shirt Graphic"] == nil then -- shirt doesn't exist
    Instance.new("ShirtGraphic").Parent = Character
    wait()
    Character["Shirt Graphic"].Graphic = "http://www.roblox.com/asset/?id=(ID)"
else -- shirt exists 
	Character["Shirt Graphic"].Graphic = "http://www.roblox.com/asset/?id=(ID)" i
end

2 comments

0

I see that. Although, your check for if the shirt graphic needs to be before line 11 since that is where the script errors. I'll edit the answer to show how to fix that.

1

Thank you so much

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