Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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
0
Thank you so much! :D PenguinAwesome_7 4 — 3y
0
No problem, accept my answer if it helped so we can get them sweet sweet rep points LeedleLeeRocket 1257 — 3y
Ad

Answer this question