Hello! I am currently making a cutscene for my game and in the cutscene, I want to replace the Player’s Shirt and Pants.
I thought it would be easy to program, however, for some reason in the cutscene the Player doesn’t have any clothes. The output doesn’t give me any errors.
The cutscene starts with a LocalScript firing a RemoteEvent. Then, a Server Script receives that and creates new clothing for the Player, fires the same RemoteEvent again, and then the cutscene plays on the client.
This is the Server Script that makes new clothing for the Player:
local DreamBarnCutsceneActivateRemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("DreamBarnCutsceneActivateEvent")
local TpPart = game.Workspace:WaitForChild("DreamCutsceneBarnCamParts"):WaitForChild("PlayerTpPart")
DreamBarnCutsceneActivateRemoteEvent.OnServerEvent:Connect(function(player)
local Shirt = Instance.new("Shirt")
local Pants = Instance.new("Pants")
Shirt.Parent = player.Character
Pants.Parent = player.Character
Shirt.Name = "Shirt"
Pants.Name = "Pants"
Shirt.ShirtTemplate = "rbxassetid://17175930056"
Pants.PantsTemplate = "rbxassetid://129459077"
player.Character:WaitForChild("HumanoidRootPart").CFrame = TpPart.CFrame
DreamBarnCutsceneActivateRemoteEvent:FireAllClients()
end)
Any help?
1 Like
There’s an instance in the Humanoid called a HumanoidDescription with properties of accessory and clothing IDs, maybe you could use that?
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local humDesc : HumanoidDescription = hum:WaitForChild("HumanoidDescription")
humDesc.Pants = 129459077 --If it's supposed to be a string just put quotation marks
humDesc.Shirt = 17175930056 --same thing here
2 Likes
You could do:
game.Player.PlayerAdded:Connect(Function(Player)
Player.CharacterApperance = 0 --<--- you can create an avatar on a real roblox account, save it, and get its appernce. then put it here
end)
A few things you migt like about this:
- You have to have all the items for the avatar
- You must have this character saved at all times, otherwise, it will change to a bacon avatar.
You Could Also Use This:
game.Player.PlayerAdded:Connect(Function(Player)
Player.Character:FindFirstChild("Humanoid").Pants = 0 --<-- Enter Pants ID
Player.Character:FindFirstChild("Humanoid").Shirt= 0 --<-- Enter Shirt ID
end)
-------- You can repeat that with "Hair" ------------------------------
1 Like
Thanks for your Reply. However, I am not trying to change the Player’s clothing when they join the game, I am trying to change their clothing for a Cutscene.
1 Like
Hey! Thanks for the Reply. Is this supposed to be in a LocalScript or a Server Script
1 Like
I believe it’s meant for a server script (considering the event is received on the server ),
so try replacing the clothes part of your script with what’s above and see what happens
1 Like
Yeah, I did. It gave me an error when using Strings with the Roblox Asset ID, so I deleted the strings and replaced them with the numbers. However, the Player’s Shirt and Pants didn’t change for some reason.
1 Like
Can I see what you currently have in the script?
1 Like
Sure.
local DreamBarnCutsceneActivateRemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("DreamBarnCutsceneActivateEvent")
local TpPart = game.Workspace:WaitForChild("DreamCutsceneBarnCamParts"):WaitForChild("PlayerTpPart")
DreamBarnCutsceneActivateRemoteEvent.OnServerEvent:Connect(function(player)
local humDesc : HumanoidDescription = player.Character:WaitForChild("Humanoid"):WaitForChild("HumanoidDescription")
humDesc.Shirt = 17175930056
humDesc.Pants = 129459077
player.Character:WaitForChild("HumanoidRootPart").CFrame = TpPart.CFrame
DreamBarnCutsceneActivateRemoteEvent:FireAllClients()
end)
1 Like
If you tried printing humDesc, and printed humDesc.Shirt and humDesc.Pants, would the output return the regular clothes a player is wearing, or the clothes you set?
EDIT: Just a thought, but it might be possible that the old Shirt and Pants instances (with the regular clothing ID’s) still exist, and the clothing IDs aren’t overwritten. You could try looking for them and deleting them so the clothes are replaced, though I’m not sure if it’ll work.
1 Like
I just ran the code on the Client and the Server, and both printed the correct IDs for the Shirt and Pants. However, when I look in the Workspace and I click on the Character’s Shirt and Pants, they both have the Original IDs.
1 Like
Yeah, so I suppose you can run your original code, but delete the original Shirt and Pants instances first so they get replaced
1 Like
Hi there, could you try changing the ShirtTemplate
and PantsTemplate
properties of the shirt and the pants instead? You must also assign the web URL of the shirt/pants instead of just the ID.
For example:
Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=17175930056"
Pants.PantsTemplate = "http://www.roblox.com/asset/?id=129459077"
1 Like
Hey! Thanks for your Reply. I just ran your code, and it gives me an error saying:
10:49:19.208 ServerScriptService.DreamBarnServerScript:9: attempt to index number with 'ShirtTemplate' - Server - DreamBarnServerScript:9
1 Like
How would I make a new Shirt and Pants without deleting the Original?
1 Like
As @ThatsRafa just said, you can just overwrite the ShirtTemplate/PantsTemplate of the player’s clothing
If writing the whole web URL doesn’t work, try just using the ID
Just realized that you most likely mean being able to return the player back to their original clothing, just keep the old IDs as variables and set the Templates back when you need to
1 Like
Okay, so I made some new code, and for some reason, the Player is naked. I looked inside of the Character’s Model, and the new Shirt and Pants are there with the correct IDs, however, they don’t show up on the actual Character.
This is the code I wrote:
local DreamBarnCutsceneActivateRemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("DreamBarnCutsceneActivateEvent")
local TpPart = game.Workspace:WaitForChild("DreamCutsceneBarnCamParts"):WaitForChild("PlayerTpPart")
DreamBarnCutsceneActivateRemoteEvent.OnServerEvent:Connect(function(player)
local OriginalShirtValue = Instance.new("IntValue")
local OriginalPantsValue = Instance.new("IntValue")
OriginalShirtValue.Parent = game:GetService("ReplicatedStorage")
OriginalPantsValue.Parent = game:GetService("ReplicatedStorage")
local humDesc : HumanoidDescription = player.Character:WaitForChild("Humanoid"):WaitForChild("HumanoidDescription")
for i, v in pairs(player.Character:GetChildren()) do
if v:IsA("Shirt") or v:IsA("Pants") then
v:Destroy()
end
end
OriginalShirtValue.Value = humDesc.Shirt
OriginalPantsValue.Value = humDesc.Pants
local newShirt = Instance.new("Shirt")
local newPants = Instance.new("Pants")
newShirt.ShirtTemplate = "rbxassetid://17175930056"
newPants.PantsTemplate = "rbxassetid://129459077"
newShirt.Parent = player.Character
newPants.Parent = player.Character
player.Character:WaitForChild("HumanoidRootPart").CFrame = TpPart.CFrame
DreamBarnCutsceneActivateRemoteEvent:FireAllClients()
print(humDesc.Shirt)
print(humDesc.Pants)
end)
1 Like
Sadly I’m not sure how to solve this problem. I did stumble upon this article, where they had to change the IDs by 1
https://www.reddit.com/r/robloxgamedev/comments/aoi8fh/how_would_i_go_about_changing_a_players_clothing/
Hope you solve your problem!
1 Like
I have done some fooling around and this works.
the shirt: Pastor shirt - Roblox
then the pants: Black Slacks - Roblox
for _, v in player.Character:GetChildren() do
if v:IsA("Shirt") or v:IsA("Pants") then
v:Destroy()
end
end
local Shirt = Instance.new("Shirt")
local Pants = Instance.new("Pants")
Shirt.Name = "Shirt"
Pants.Name = "Pants"
Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=17175930039"
Pants.PantsTemplate = "http://www.roblox.com/asset/?id=129459076"
Shirt.Parent = player.Character
Pants.Parent = player.Character
player.Character:WaitForChild("HumanoidRootPart").CFrame = TpPart.CFrame
DreamBarnCutsceneActivateRemoteEvent:FireAllClients()
or you could also do this
for _, v in player.Character:GetChildren() do
if v:IsA("Shirt") then
v.ShirtTemplate = "http://www.roblox.com/asset/?id=17175930039"
elseif v:IsA("Pants") then
v.PantsTemplate = "http://www.roblox.com/asset/?id=129459076"
end
player.Character.HumanoidRootPart.CFrame = TpPart.CFrame
DreamBarnCutsceneActivateRemoteEvent:FireAllClients()
end
Yo! Thank you so much! This worked.