You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to change the shirt from player.
What is the issue? It all worked, but it gives a blanked shirt.
What solutions have you tried so far? I tryed a lot, even a outer shirt id. but it will not work. and if I put this text ‘http://www.roblox.com/asset/?id=2489164735’ myself in the shirt id, it work dirrectly. But I see the Id changed itself. Can someone help me? I want this shirt ID: 2489164735
local Box = script.Parent.Parent.IDBox
local db = false
local player = game.Players.LocalPlayer
local Character = game.Workspace:FindFirstChild(player.Name)
local MarketplaceService = game:GetService("MarketplaceService")
Box.Text = ''
script.Parent.MouseButton1Click:Connect(function()
if db == false then
db = true
Box.TextEditable = false
local OrriginalText = Box.Text
Box.Text = 'Loading'
wait(0.5)
local success, response = pcall(function()
local text = tonumber(OrriginalText)
local stuf = MarketplaceService:GetProductInfo(text)
if stuf.AssetTypeId == 11 then
print(stuf.AssetId)
Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..stuf.AssetId
Box.Text = 'Correct changed!'
else
Box.Text = 'No Shirt!'
end
end)
if not success then
Box.Text = 'No Correct ID!'
end
wait(2)
Box.Text = OrriginalText
db = false
Box.TextEditable = true
end
end)
If you did add the string “”, I encountered this sometimes in the past, some clothes did change and some changed to blank and failed to load.
Only when I used InsertService:LoadAsset(assetId) to get the model with the clothing in it, it worked for me. InsertService:LoadAsset(assetId)
For instance:
To get the shirt:
local assetId = 123456 --Random id
local success, shirt = pcall(function()
return game:GetService("InsertService"):LoadAsset(assetId) --Get the model with the asset
end)
if success then --If it loaded successfully
shirt = shirt:FindFirstChildOfClass("Shirt")
--Destroy the current shirt and replace it with the new one
else --Shirt wasn't loaded successfully
warn(shirt) --Warn the error that caused the loading to fail.
end
@kalabgs yeah, as far as I know, it doesn’t matter whether you use the longer one or the shorter one.
local Box = script.Parent.Parent.IDBox
local db = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ChangeShirt = ReplicatedStorage:WaitForChild("ChangeShirt")
Box.Text = ''
script.Parent.MouseButton1Click:Connect(function()
if db == false then
db = true
Box.TextEditable = false
local OrriginalText = Box.Text
Box.Text = 'Loading'
wait(0.5)
local Id = tonumber(OrriginalText)
local Bool = ChangeShirt:InvokeServer(Id)
Box.Text = Bool
wait(2)
Box.Text = OrriginalText
db = false
Box.TextEditable = true
end
end)
Script
local MarketplaceService = game:GetService("MarketplaceService")
local Insert = game:GetService("InsertService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ChangeShirt = ReplicatedStorage:WaitForChild("ChangeShirt")
function Change(Player,ShirtId)
local Return = "Error"
local success,stuf = pcall(function()
return MarketplaceService:GetProductInfo(ShirtId)
end)
if success then
if stuf.AssetTypeId == 11 then
print(stuf.AssetId)
local Shirt = Player.Character:FindFirstChildOfClass("Shirt")
if Shirt then Shirt:Destroy() end
local Obj = Insert:LoadAsset(ShirtId):GetChildren()[1]
Obj.Parent = Player.Character
Return = 'Correct changed!'
else
Return = 'No Shirt!'
end
else
Return = 'No Correct ID!'
end
return Return
end
ChangeShirt.OnServerInvoke = Change
And put a RemoteFunction called “ChangeShirt” in ReplicatedStorage.