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

Unexpected URL error?

Asked by
JJ_B 250 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by 8 years ago

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)
1
This gives me another error; "Workspace.clothes:11: bad argument #3 to 'ShirtTemplate' (string expected, got nil)" :( JJ_B 250 — 8y
0
Whoops! My bad lol! MessorAdmin 598 — 8y
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." JJ_B 250 — 8y
0
Yes please, I'm not exactly sure how to do that considering I get errors every time I try. JJ_B 250 — 8y
View all comments (3 more)
0
Alright! No problem! MessorAdmin 598 — 8y
0
Inevitable, another error (sorry to bother you so much) 'Workspace.clothes:9: attempt to concatenate local 'Shirt_ID' (a nil value)' >:( JJ_B 250 — 8y
0
Its fixed MessorAdmin 598 — 8y
Ad

Answer this question