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

Unexpected URL error?

I made a script that puts you in your normal clothes when you type "/clothes." However, the script gives me an error when I say this and turns my character nude. The error is Image failed to load Workspace.Player1.Humanoid Clothes : nil because Unexpected URL Here is the script:

game.Workspace.ChildAdded:connect(function(char)
	if char:FindFirstChild("Humanoid") then
		local p = game.Players:FindFirstChild(char.Name)
		if p then
			if char:FindFirstChild("Shirt") then
				sh = char.Shirt.ShirtTemplate
			else
				local d = Instance.new("Shirt")
				d.Parent = char
				d.Name = "Shirt"
				pa = d.ShirtTemplate
			end
			if char:FindFirstChild("Pants") then
				pa = char.Pants.PantsTemplate
			else
				local d = Instance.new("Pants")
				d.Parent = char
				d.Name = "Pants"
				pa = d.PantsTemplate
			end
		end
	end
end)

function onChatted(msg, recipient, speaker) 
msg = string.lower(msg) 

if (msg == "/clothes") then 
speaker.Character.Pants.PantsTemplate = tostring(pa)
speaker.Character.Shirt.ShirtTemplate = tostring(sh)
end 

end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 

Please help D:

1 answer

✓ Accepted answer

Quite a simple mistake. But, instead of making another let's fix the entire code shall we?

Its fixed. Just so I have proof. http://i.imgur.com/LLq6A6L.gif

local Players =game.Players
local Prefix="http://www.roblox.com/asset/?id="

function GetSplit(msg)
	local a = nil
	for i = 1,#msg do
		if msg:sub(i,i) == "," then
			a = i+1
			break
		end
	end
	if a ~= nil then
		return {msg:sub(10,a-2), msg:sub(a)}
	else
		return nil
	end
end

function Change(char, shirt, pant)
    if char:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(char)
        if char:FindFirstChild("Shirt",true) then
            char.Shirt.ShirtTemplate = Prefix..shirt
        else
            local Shirt = Instance.new("Shirt", char)
            Shirt.ShirtTemplate = Prefix..shirt
        end
        if char:FindFirstChild("Pants",true) then
            char.Pants.PantsTemplate = Prefix..pant
        else
            local Pants = Instance.new("Pants", char)
            Pants.PantsTemplate = Prefix..pant
        end
    end
end

Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(Message)
        if Message:lower():sub(1,3) == "/e " then -- /e fix
            Message = Message:sub(4)
        end
        if Message:lower():sub(1,8) == "/clothes" then
			local Table = GetSplit(Message)
			local Shirt,Pants = Table[1],Table[2]
			if type(Table) == "table" then
				Change(Player.Character, Shirt, Pants) -- So I chatted /clothes 432070756,417042178 and it worked fine
			else
				warn("Error occured")
			end
        end
    end)
end)

7 comments

1

This gives me another error; "Workspace.clothes:11: bad argument #3 to 'ShirtTemplate' (string expected, got nil)" :(

0

Whoops! My bad lol!

0

Ohhh, this script depends on pre-defined clothing IDs, but my original script was to get the individual player's clothing and THEN apply it when they said "/clothes."

0

Yes please, I'm not exactly sure how to do that considering I get errors every time I try.

0

Alright! No problem!

0

Inevitable, another error (sorry to bother you so much) 'Workspace.clothes:9: attempt to concatenate local 'Shirt_ID' (a nil value)' >:(

0

Its fixed

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