So I have a game I’m working on where I will set the player’s shirt and pants based on a character they select. The problem I’m having is that sometimes a player will be loaded with the shirt and pants ID, and I checked through the workspace and their shirt ID are properly set, but for some reason it does not show it. They only appear without clothes on the client, so other players aren’t able to see it but I want to know how to fix this?
The only code I have setting the clothing is apart of my maingame server script:
GivePlyrChar.OnServerEvent:Connect(function(player, NPC)
if Character == "John" then
for i,v in pairs(player.Character:GetChildren()) do
if v.ClassName == "Accessory" then
v:Remove()
end
end
if not player.Character:FindFirstChild('Shirt') then
Instance.new("Shirt", player.Character)
end
if not player.Character:FindFirstChild('Pants') then
Instance.new("Pants", player.Character)
end
player.Character:WaitForChild('Shirt').ShirtTemplate = "rbxassetid://398633582"
player.Character:WaitForChild('Pants').PantsTemplate = "rbxassetid://398633811"
player.Character:WaitForChild('Head').face.Texture = "rbxassetid://23931977"
local clonedHair = game.ReplicatedStorage.Characters.John.NerdHair:Clone()
clonedHair.Parent = player.Character
clonedHair.Handle.CFrame = player.Character.Head.CFrame * CFrame.new(0,2,0)
clonedHair.Handle.AccessoryWeld.Part1 = player.Character.Head
local nametag = game.ReplicatedStorage:WaitForChild('nametag'):Clone()
nametag.Parent = player.Character
nametag.BillboardGui.TextLabel.Text = "John"
local newWeld = Instance.new("Weld", nametag)
newWeld.Part0 = nametag
newWeld.Part1 = player.Character.Head
nametag.Anchored = false
newWeld.C0 = CFrame.new(0, -1.8, 0)
nametag.CanCollide = false
player.Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
end
So when the player is teleported to the map, only sometimes do they appear without clothes. I also noticed when they get sent back to the lobby, it sometimes also shows them with no clothes.
Update: Alright so now I noticed that they are both appearing without clothes. Interesting.
Make sure that the clothing items and other accessories you’re trying to give to the player are being replicated correctly to the client. You’re using the WaitForChild method, which is generally safe, but ensure that the assets (Shirt , Pants , Head , NerdHair , nametag , etc.) are all properly placed in the ReplicatedStorage and can be cloned to the player’s character on the client.
Roblox uses network ownership to determine which parts of the game are controlled by the server and which are controlled by the client. If you’re adding items to a player’s character on the client-side, you might be running into network ownership issues. You should perform character customization on the server to ensure consistency.
Check whether the code you provided is being executed as expected. Verify that the GivePlyrChar.OnServerEvent event is being fired when a player selects a character, and the Character variable is being set correctly.
The assets are placed inside of replicatedstorage and are apart of each character, inside of a “Characters” folder, so I’m cloning those items and parenting them all to the player.
The code for giving the players their characters is in the original post.
GivePlyrChar.OnServerEvent:Connect(function(player, NPC)
if Character == "John" then
for i,v in pairs(player.Character:GetChildren()) do
if v.ClassName == "Accessory" then
v:Remove()
end
end
if not player.Character:FindFirstChild('Shirt') then
Instance.new("Shirt", player.Character)
end
if not player.Character:FindFirstChild('Pants') then
Instance.new("Pants", player.Character)
end
player.Character:WaitForChild('Shirt').ShirtTemplate = "rbxassetid://398633582"
player.Character:WaitForChild('Pants').PantsTemplate = "rbxassetid://398633811"
player.Character:WaitForChild('Head').face.Texture = "rbxassetid://23931977"
local clonedHair = game.ReplicatedStorage.Characters.John.NerdHair:Clone()
clonedHair.Parent = player.Character
clonedHair.Handle.CFrame = player.Character.Head.CFrame * CFrame.new(0,2,0)
clonedHair.Handle.AccessoryWeld.Part1 = player.Character.Head
local nametag = game.ReplicatedStorage:WaitForChild('nametag'):Clone()
nametag.Parent = player.Character
nametag.BillboardGui.TextLabel.Text = "John"
local newWeld = Instance.new("Weld", nametag)
newWeld.Part0 = nametag
newWeld.Part1 = player.Character.Head
nametag.Anchored = false
newWeld.C0 = CFrame.new(0, -1.8, 0)
nametag.CanCollide = false
player.Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
end
-- Assume this is a LocalScript in StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local characterSelectedEvent = ReplicatedStorage:WaitForChild("CharacterSelected")
characterSelectedEvent.OnClientEvent:Connect(function(characterName)
local player = Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
-- Remove existing character
character:Destroy()
-- Load the selected character's StarterCharacter
local starterCharacter = game.StarterPack.CharacterModels:FindFirstChild(characterName)
if starterCharacter then
local newCharacter = starterCharacter:Clone()
newCharacter.Parent = workspace
humanoid.Health = 0 -- Reset health to trigger respawning
else
warn("StarterCharacter not found for " .. characterName)
end
end)
On the server side, you can trigger the character selection using a RemoteEvent:
-- Assume this is a Script in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local characterSelectedEvent = Instance.new("RemoteEvent")
characterSelectedEvent.Name = "CharacterSelected"
characterSelectedEvent.Parent = ReplicatedStorage
characterSelectedEvent.OnServerEvent:Connect(function(player, characterName)
-- Handle character selection here
-- Apply any necessary changes to the player's data, etc.
-- You might want to validate the characterName before proceeding
-- Notify the client that the character has been selected
characterSelectedEvent:FireClient(player, characterName)
end)