Items being given to all players (not client based only)

– Server

RetrieveItem.OnServerEvent:Connect(function(player, assetType, id)
	local AssetTypeId = MarketplaceService:GetProductInfo(id).AssetTypeId

	if AssetTypeId ~= 8 and AssetTypeId ~= 11 and AssetTypeId ~= 12 and AssetTypeId ~= 18 and AssetTypeId ~= 41 and AssetTypeId ~= 42 and AssetTypeId ~= 43 and AssetTypeId ~= 44 and AssetTypeId ~= 45 and AssetTypeId ~= 46 and AssetTypeId ~= 47 then
		return
	end
	
	local Success, Model = pcall(function()
		return InsertService:LoadAsset(id)
	end)

	if Success then
		for i,v in pairs(Model:GetDescendants()) do
			if v:IsA('LuaSourceContainer') or v:IsA('BackpackItem') then
				v:Destroy()
			end
		end

		local Accessory = Model:GetChildren()[1]
		local CurrentFolderItem = CustomiseHolder:FindFirstChild(assetType)

		if assetType == 'Hat' or assetType == 'Hair' or assetType == 'Accessory' then
			Accessory.Name = assetType .. ' - ' .. id
			Accessory.Parent = CustomiseHolder.Accessories
			wait()
			Accessory:Destroy()
		else
			if assetType == 'Face' then
				CurrentFolderItem.Texture = Accessory.Texture
			elseif assetType == 'Shirt' then
				CurrentFolderItem.ShirtTemplate = Accessory.ShirtTemplate
			elseif assetType == 'Pants' then
				CurrentFolderItem.PantsTemplate = Accessory.PantsTemplate
			end
			
			Accessory:Destroy()
		end
		
		Model:Destroy()
	end
end)

– Client

CustomiseHolder.Accessories.ChildAdded:Connect(function(accessory)
	wait()
	
	local Hat = 0
	local Hair = 0
	local Accessory = 0

	for _, v in pairs(Dummy:GetChildren()) do
		if v.Name == accessory.Name then return end
		
		if string.sub(accessory.Name, 1, 6) == 'Hat - ' then
			if string.sub(v.Name, 1, 6) == 'Hat - ' then
				Hat = Hat + 1
				
				if Hat >= 5 then
					return
				end
			end
		elseif string.sub(accessory.Name, 1, 7) == 'Hair - ' then
			if string.sub(v.Name, 1, 7) == 'Hair - ' then
				Hair = Hair + 1
				
				if Hair >= 5 then
					return
				end
			end
		elseif string.sub(accessory.Name, 1, 12) == 'Accessory - ' then
			if string.sub(v.Name, 1, 12) == 'Accessory - ' then
				Accessory = Accessory + 1
				
				if Accessory >= 5 then
					return
				end
			end
		end
	end
		
	local Attach0 = accessory.Handle:FindFirstChildWhichIsA('Attachment')
	local Attach1 = Dummy:FindFirstChild(Attach0.Name, true)

	local Weld = Instance.new('Weld')
	Weld.Parent = accessory.Handle
	Weld.Part0 = Attach0.Parent
	Weld.Part1 = Attach1.Parent
	Weld.C0 = Attach0.CFrame
	Weld.C1 = Attach1.CFrame

	accessory.Parent = Dummy
end)

Problem is, if you have 2 players on, one player retrieves an item, they both end up getting it on their dummy. How can I go about making it so only the player who requested the item gets said item

I’m assuming the dummy is for showing the player what their customized character looks like and if so then you should create dummies for each player that joins or you just make it client sided which would probably just be best.

Dummies are client side
30 characters

Yeah just read over the code and you’re going to have to make a dummy for each player that joins on the server unless you want to have the accessories in ReplicatedStorage instead of calling LoadAsset.

I don’t want the accessories all inside RepStorage. Waste of storage having millions of clothing/accessories all stored on the game. Much easier loading them in.

Each player does get their own dummy. The problem comes from when you load the items into RepStorage, the client not knowing whose items are whose. It just knows that a child was added to the folder, and thus puts it on the players dummy. I need a way for the client to recognise which items are from the server that they requested. Same goes for clothing.

Dummy.Shirt.ShirtTemplate = CustomiseHolder.Shirt.ShirtTemplate

CustomiseHolder.Shirt:GetPropertyChangedSignal('ShirtTemplate'):Connect(function()
	Dummy.Shirt.ShirtTemplate = CustomiseHolder.Shirt.ShirtTemplate
end)

When I load a new shirt from the server, it changes the ShirtTemplate (located in RepStorage) and then Client picks up that change, and then goes to change their Dummys shirt. However, if somebody else changes the shirt, your client still picks up that it was changed.

Couldn’t you just make a new folder when a new player joins and listen for their folder to be created on the client? i.e

-- Server

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local DummyFolder = ReplicatedStorage.DummyFolder

Players.PlayerAdded:Connect(function(player)
	local PlayerAssets = Instance.new("Folder")
	PlayerAssets.Name = player.Name
	PlayerAssets.Parent = DummyFolder
end)

-- Client 

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DummyFolder = ReplicatedStorage.DummyAssets:WaitForChild(game.Players.LocalPlayer.Name)

DummyFolder.ChildAdded:Connect(function()
	-- add asset to dummy here 
end)
1 Like