Players can't see clothing from mannequins on other players

I’ve been using this cute mannequin model where it shows a selected box around the mannequin’s body parts when a player hovers their mouse over it. Then, a small gui pops up, where the player can try on and buy the clothing.

This seems to work fine!

However, when you try on the clothing, it does not show you wearing the selected clothing to other players. So it only works for individuals.

Any ideas how I can fix it so the clothing you try on appears to everyone in the server on your character?
This is the script I’m using:

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local userInput = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local marketplaceService = game:GetService("MarketplaceService")
local mannequinsFolder = workspace:WaitForChild("Mannequins")

local selected = ""

local root = script.Parent
local mainFrame = root:WaitForChild("MainFrame")
local tryButton = mainFrame:WaitForChild("TryButton")
local buyButton = mainFrame:WaitForChild("BuyButton")
local cancelButton = mainFrame:WaitForChild("CancelButton")

function setAllOff()
	for mannequinIndex, mannequinFolder in pairs(mannequinsFolder:GetChildren()) do
		for selectionIndex, selectionBox in pairs(mannequinFolder.SelectionBoxes:GetChildren()) do
			selectionBox.Visible = false
		end
	end
end

runService:BindToRenderStep("MouseHover", Enum.RenderPriority.Camera.Value - 1, function()
	local target = mouse.Target
	
	if target and target:IsDescendantOf(mannequinsFolder) then
		local mannequin = target.Parent
		local shirt = mannequin:FindFirstChild("Shirt")
		local pants = mannequin:FindFirstChild("Pants")
		local selectionFolder = mannequin:FindFirstChild("SelectionBoxes")
		
		if target.Name == "Left Arm" or target.Name == "Right Arm" then
			setAllOff()
			if shirt.ShirtTemplate ~= "" and shirt.ShirtTemplate ~= "rbxassetid://" then
				selectionFolder["Right Arm"].Visible = true
				selectionFolder["Left Arm"].Visible = true
				selectionFolder["Torso"].Visible = true
			end
		elseif target.Name == "Torso" then
			setAllOff()
			if shirt.ShirtTemplate ~= "" and shirt.ShirtTemplate ~= "rbxassetid://" then
				selectionFolder["Right Arm"].Visible = true
				selectionFolder["Left Arm"].Visible = true
				selectionFolder["Torso"].Visible = true
			else
				selectionFolder["Right Leg"].Visible = true
				selectionFolder["Left Leg"].Visible = true
				selectionFolder["Torso"].Visible = true
			end
		elseif target.Name == "Left Leg" or target.Name == "Right Leg" then
			setAllOff()
			if shirt.ShirtTemplate ~= "" and shirt.ShirtTemplate ~= "rbxassetid://" then
				selectionFolder["Right Leg"].Visible = true
				selectionFolder["Left Leg"].Visible = true
			else
				selectionFolder["Right Leg"].Visible = true
				selectionFolder["Left Leg"].Visible = true
				selectionFolder["Torso"].Visible = true
			end
		end
	else
		setAllOff()
	end
end)

mouse.Button1Down:Connect(function()
	local target = mouse.Target
	
	if target and target:IsDescendantOf(mannequinsFolder) then
		local mannequin = target.Parent
		local shirt = mannequin:FindFirstChild("Shirt")
		local pants = mannequin:FindFirstChild("Pants")
		
		if target.Name == "Left Arm" or target.Name == "Right Arm" then
			if shirt.ShirtTemplate ~= "" and shirt.ShirtTemplate ~= "rbxassetid://" then
				selected = shirt
			end
		elseif target.Name == "Torso" then
			if shirt.ShirtTemplate ~= "" and shirt.ShirtTemplate ~= "rbxassetid://" then
				selected = shirt
			else
				selected = pants
			end
		elseif target.Name == "Left Leg" or target.Name == "Right Leg" then
			if shirt.ShirtTemplate ~= "" and shirt.ShirtTemplate ~= "rbxassetid://" then
				selected = pants
			else
				selected = pants
			end
		end
		
		buyButton.RoundFrame.Label.Text = "Buy " .. selected.Name
		
		mainFrame.Visible = true
	end
end)

tryButton.MouseButton1Down:Connect(function()
	local character = player.Character
	if player.Character then
		if character:FindFirstChildOfClass(selected.ClassName) then
			character:FindFirstChildOfClass(selected.ClassName)[selected.Name .. "Template"] = selected[selected.Name .. "Template"]
		else
			local clone = selected:Clone()
			clone.Parent = character
		end
	end
end)

buyButton.MouseButton1Down:Connect(function()
	marketplaceService:PromptPurchase(player, selected.AssetId.Value)
end)

cancelButton.MouseButton1Down:Connect(function()
	mainFrame.Visible = false
end)

Thanks in advance!

The Change clothing needs to be fired by a remote event to a script. Since when the clothing goes on the player through local script only that player can see it. You need to change the clothing on a server script

2 Likes

I tried! But it seems like the script stops working when I transfer the code to the server script. image

Can you show me your code? So I can help more

Server scripts can only run when it’s a descendant of Workspace or ServerScriptService. Putting your server script inside of a GUI will do neither, so it won’t run and won’t listen for your remote. You should move the script to ServerScriptService instead.

1 Like

I tried doing this, but as soon as I take it out of the GUI, it stops working. Any other solutions that I could try?

Server scripts do not run on the client. You would need to set up remotes from the client to server to do what you need.

I recommend that when tryButton is clicked, you fire a remote event to the server with the shirt id and pants id you want the player to wear. The server then can change out the shirt and pants of the player to the one you want.

English is sadly my 4th language, so I have trouble understanding this. How would you recommend I’d try this? Would it just be scripting?