How To Make Data Store For Clothing?

Like Title Says, I Need To Know How To Make Data Store, So I Don’t Need To Equip Clothing Everytime I Leave Or Dies.

I Looked Into DevForum And Youtube, But None Explain How To Make It.

I Already Maked The Clothing Shop System, Here Is It.

local Players = game:GetService("Players")

player = script.Parent.Parent.Parent.Parent.Parent.Parent

coins = player.leaderstats.Gold

price = 40

clothing = game.Lighting.FashionCatalog.BenBlackSuit:FindFirstChild("Shirt")

script.Parent.MouseButton1Click:Connect(function()
	local Character = player.Character or player.CharacterAdded:Wait()
		if coins.Value >= price then
		coins.Value = coins.Value - price
		local foundShirt = player.Character:FindFirstChildWhichIsA("Shirt")
		if not foundShirt then
		local a = clothing:Clone()
		a.Parent = Character
		else if foundShirt then
		foundShirt:remove()
		local a = clothing:Clone()
		a.Parent = Character
	 end
  end
end
end)

Not good practice.


I recommend you use Instance:Destroy(), Instance:Remove() is Deprecated, and Using it does not Destroy the item, Instead it sets it Parent to nil, the Equivilent of doing:

Instance.Parent = nil

For a DataStore that Stores clothing, I recommend Saving the Data for it, maybe you can have this type of Data:

userData = {
CurrentShirt = ""; -- the Name or Id of the Shirt
CurrentPants = ""; -- the Name or Id of the Pants

Inventory = {} -- a Table so you can Store what the Player owns
}

I Also reccomend you use RemoteEvents to handle Data instead of having a Script embedded within the Player, Only then, you would need to make sure that it cannot be exploited with Sanity Checks, you should Handle the Transactions on the Server, so it will replicate to everything, and then you can return the Data, Handle the Details on the Client.

2 Likes

I won’t give you all of the code required, but basically you need to enable “Enable Studio Access to API Services” and get the service and datastore at the top of your script, like this:

local dataService = game:GetService("DataStoreService")
local ds = dataService:GetDataStore("NAMEHERE")

There are also a few pages on the docs about datastore service

1 Like

And like @DasKairo said, I suggest removing :remove() as its deprecated, use :Destroy()

Also, In case you are confused, here are instructions on how to enable the api services:


1 Like