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

Why doesn't this script work?

This is a script inside a textbutton.For some reasons it doesn't work nor does it give me any errors.It should change my Shirt and Pants.

Char = script.Parent.Parent.Parent.Parent.Character
sh = Char.Shirt
pa = Char.Pants
st = sh.ShirtTemplate
pt = pa.PantsTemplate


function onClick(mouse)
		if Char:FindFIrstChild("Shirt") then
  	  		Char.Shirt:Destroy()
		end
		if Char:FindFIrstChild("Pants") then
   			Char.Pants:Destroy()
		end
		s = Instance.new("Shirt", Char)
		s.ShirtTemplate = "http://www.roblox.com/asset/?id=255758532"
		p = Instance.new("Pants", Char)
		p.PantsTemplate = "http://www.roblox.com/asset/?id=255758581"
		script.Parent.Text = "Wear Off"
end
script.Parent.MouseButton1Click:connect(onClick)

1 answer

✓ Accepted answer

Sometimes Char takes a bit to load, so do this:

Char = script.Parent.Parent.Parent.Parent.Character
repeat wait() until Char
sh = Char.Shirt
pa = Char.Pants
st = sh.ShirtTemplate
pt = pa.PantsTemplate


function onClick(mouse)
        if Char:FindFIrstChild("Shirt") then
            Char.Shirt:Destroy()
        end
        if Char:FindFIrstChild("Pants") then
            Char.Pants:Destroy()
        end
        s = Instance.new("Shirt", Char)
        s.ShirtTemplate = "http://www.roblox.com/asset/?id=255758532"
        p = Instance.new("Pants", Char)
        p.PantsTemplate = "http://www.roblox.com/asset/?id=255758581"
        script.Parent.Text = "Wear Off"
end
script.Parent.MouseButton1Click:connect(onClick)


2 comments

0

FindFIrstChild is not a valid member of Model

0

"FindFIrstChild" You typed it in wrong, It's "FindFirstChild"

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