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

Pants/Shirt changing script not working, no errors?

So. I'm making a locker, but when I try to change the character's Shirt/Pants, it won't do anything nor print any errors.

function onTouch(part) 
	local human = part.Parent:findFirstChild("Humanoid") 
	if human ~= nil then 
		local shirt = part.Parent:FindFirstChild("Shirt")
		local pants = part.Parent:FindFirstChild("Pants")
		local shirtID = 328958545
		local pantsID = 328960599
		if shirt == nil then
			local s = Instance.new("Shirt", part.Parent)
			s.Name = "Shirt"
		if pants == nil then
			local p = Instance.new("Pants", part.Parent)
			p.Name = "Pants"
		end
		pants.PantsTemplate = ("http://www.roblox.com/asset/?id="..pantsID)
		pants.ShirtTemplate = ("http://www.roblox.com/asset/?id="..shirtID)
		end
	end
end
script.Parent.Touched:connect(onTouch)

And no. The script is not disabled.

Hierarchy

>Model
>>Spawn
>>>Clothes --This Is The Script

Edit

local n=0 
local function dp() 
	 if true then 
		n=n+1
		print(n) 
	end 
end

function onTouch(part) 
	local human = part.Parent:findFirstChild("Humanoid") 
	dp()
	if human ~= nil then 
		dp() --Counts to here (2)
		local shirt = part.Parent:FindFirstChild("Shirt")
		local pants = part.Parent:FindFirstChild("Pants")
		local shirtID = 328958545
		local pantsID = 328960599
		if shirt == nil then --Problems here
			local s = Instance.new("Shirt", part.Parent)
			s.Name = "Shirt"
			dp()
		if pants == nil then --Problems here
			local p = Instance.new("Pants", part.Parent)
			p.Name = "Pants"
			dp()
		end
		pants.PantsTemplate = ("rbxassetid://"..pantsID)
		dp()
		shirt.ShirtTemplate = ("rbxassetid://"..shirtID)
		dp()
		end
	end
end
script.Parent.Touched:connect(onTouch)

1 answer

✓ Accepted answer

On line 21, There should of been a end to close the if statement, or the usage of elseif to iterate through the rest of the code.

function onTouch(part)
	local human = part.Parent:findFirstChild("Humanoid")
	if human ~= nil then
	        local shirt = part.Parent:FindFirstChild("Shirt")
	        local pants = part.Parent:FindFirstChild("Pants")
	        local shirtID = 328958545
	        local pantsID = 328960599
	        if shirt == nil then
	        	local s = Instance.new("Shirt", part.Parent)
	        	s.Name = "Shirt"
			end -- Missing an end or elseif
	        if pants == nil then
	       		local p = Instance.new("Pants", part.Parent)
	        	p.Name = "Pants"
	        end
	        pants.PantsTemplate = ("http://www.roblox.com/asset/?id="..pantsID)
	        pants.ShirtTemplate = ("http://www.roblox.com/asset/?id="..shirtID)
	end
end

script.Parent.Touched:connect(onTouch)

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