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

have a way to add shirt for a player who touched a part by a script?

Hello!, i have a script that works very well, but sometimes it give me a error on console saying like "Shirt was not found on (player name)", is there any way to if script dont found the shirt on avatar, the script create a shirt and put inside the player who touched the part? heres my script :

local ChangerPart = script.Parent
local ShirtTemplate = "http://www.roblox.com/asset/?id=1234"
local PantsTemplate = "http://www.roblox.com/asset/?id=1234"

ChangerPart.Touched:Connect(function(TouchPart)
	if TouchPart and TouchPart.Parent and TouchPart.Parent:FindFirstChild("Humanoid") then
		print(TouchPart.Parent.Name ..  " - Changed clothes")
		local Character = TouchPart.Parent
		Character.Shirt.ShirtTemplate = ShirtTemplate
		Character.Pants.PantsTemplate = PantsTemplate
		wait(3)
	end
end)

Also this script its from a youtube tutorial channel, but i made some changes!

1 answer

✓ Accepted answer

Add this after line 8:

if Character.Shirt == nil then --check if the character has a shirt, if it doesn't then it the script will return nil
	Instance.new("Shirt", Character) --make a new shirt instance and parent it to the character
end

2 comments

0

Thank you so much! :D

0

No problem, accept my answer if it helped so we can get them sweet sweet rep points

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