hey there, I have pasted that script on the ServerScriptService as normal script, however it still doesn’t seems to work still, and the warning message doesn’t seems to appear in the OutPut, and we are making that script in ServerScriptService for make table and storing the value of the shirt/pants template right? but I couldn’t understand that due to my low scripting skill, help is still gladly needed thank you, also there is screenshot of pasted script and proof that no warning have been logged in the output, it would be awesome if you could help me with, thank you.
That error is from a different script, in which you are trying to load an asset.
I understand you are starting in scripting and dont worry thats pretty cool and I’d love to help.
Lets start from zero, I tested this script and does exactly what you want, when player change Pants or Shirt its gets saved for the player, when leaves its saved on DataStore, and when joins agains their character will spawn with the right clothes they saved previously.
Create a new blank file and paste this script in ServerScriptService, make sure it has DataStore saving feature enabled for the place and publish it to Roblox:
local DataStoreService = game:GetService("DataStoreService")
local PlayerCloths_DSS = DataStoreService:GetDataStore("PlayerCloths")
-- WHEN PLAYER JOINS - READ DATASTORE
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
warn("Creating Folder and Values for player:", player)
local newFolder = Instance.new("Folder")
newFolder.Name = "MyCloths"
newFolder.Parent = player
local shirtVal = Instance.new("StringValue")
shirtVal.Name = "ShirtVal"
shirtVal.Parent = newFolder
local pantsVal = Instance.new("StringValue")
pantsVal.Name = "PantsVal"
pantsVal.Parent = newFolder
warn("Waiting for Shirt and Pants to exist in player")
local shirtInstance = player.Character:WaitForChild("Shirt")
local pantsInstance = player.Character:WaitForChild("Pants")
local data
local success, errormessage = pcall(function()
data = PlayerCloths_DSS:GetAsync(player.UserId, {shirtInstance, pantsInstance})
end)
if success then
if data then
warn("DSS data exist for player, updating")
shirtInstance.ShirtTemplate = data[1]
pantsInstance.PantsTemplate = data[2]
shirtVal.Value = data[1]
pantsVal.Value = data[2]
else
warn("New player, no data in DSS yet")
-- Setting the default StarterCharacter data
shirtVal.Value = shirtInstance.ShirtTemplate
pantsVal.Value = pantsInstance.PantsTemplate
end
else
warn(errormessage)
end
-- Listening when Shirt or Pants get changed by server side
shirtInstance.Changed:Connect(function(prop)
if prop == "ShirtTemplate" then
shirtVal.Value = shirtInstance.ShirtTemplate
end
end)
pantsInstance.Changed:Connect(function(prop)
if prop == "PantsTemplate" then
pantsVal.Value = pantsInstance.PantsTemplate
end
end)
end)
-- WHEN PLAYER LEAVES - SAVES DATASTORE
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
PlayerCloths_DSS:SetAsync(player.UserId, {player.MyCloths.ShirtVal.Value, player.MyCloths.PantsVal.Value} )
end)
if success then
print ("Player Data successfully saved")
else
print ("Error saving data")
warn(errormessage)
end
end)
And create 2 parts in workspace called, ShirtBTN and PantsBTN. Place a ClickDetector inside them. Its just for quick testing, the buttons will change the cloths of the player randomly on click. And for the buttons system just paste this script in ServerScriptService too as a different script than the previous one:
local InsertService = game:GetService("InsertService")
local ShirtsIDs = {6680877688, 7713626261, 11612658975, 6780970545}
local PantsIDs = {6314613214, 6752704115, 5053949817, 11679597207}
game.Workspace:WaitForChild("ShirtBTN").ClickDetector.MouseClick:Connect(function(player)
local chooseRandom = ShirtsIDs[math.random(1, #ShirtsIDs)]
player.Character.Shirt.ShirtTemplate = InsertService:LoadAsset(chooseRandom).Shirt.ShirtTemplate
end)
game.Workspace:WaitForChild("PantsBTN").ClickDetector.MouseClick:Connect(function(player)
local chooseRandom = PantsIDs[math.random(1, #PantsIDs)]
player.Character.Pants.PantsTemplate = InsertService:LoadAsset(chooseRandom).Pants.PantsTemplate
end)
I just copied some IDs from Roblox Catalog randomly for the Pants and Shirts, you can replace the ids, but thats not important, cause we need to connect YOUR changing clothing script we’ll not use this random one, this is only for testing
Im sending you the file so would be easier to test, a lil video. Im using a blank model as the StarterCharacter womanRig for the test:
The place file:
SaveChar.rbxl (61.6 KB)
thank you for your help, I have pasted these scripts as you said, however things doesn’t still come in the way, the BTN parts doesn’t change the StarterCharacter’s clothing at all, (but I want player to wear clothes that isn’t worn randomly so it could be more awesome if you could edit the random pick system on BTN part, and also there will be four mannequins that gives player the clothings, so we can make four BTN parts with different numbers like ShirtBTN1 and ShirtBTN2 parts and make it work.) and also there is “HTTP 403 Forbidden” error from 2nd script and “Unable to assign property Value. string expected, got Instance” error from 1st script.
and thanks for showing me file of that while I was writing this, I appreciate that.
also I will show you one screenshot of that in-dev clothing part you suggested to me and output messages. thank you so much.
-mari
Nonono, I dont mean you should change the shirts/pants randomly. I stated that the buttons I added are for testing. So you can see the Saving system script works, and you can use it with your own changing clothing system.
What I want is to help you step by step, if you download the file I sent, and enable Datastore saving, and you make it to work is the first step, cause the script works.
Then, try to understand whats happening in the script. Then in your game, make sure you are changing the Shirt/Pants on server side, and my script will save that into datastore. If you use the script found in the file I sent. Or copy the script again from my message (I edited an error of the previous one)
this is an footage of me bringing that StarterCharacter I use in wanted game but it does not work for odd reasons, probably because character is an r6 or something… who knows
(I have re-tested it with r15 StarterCharacter that you used and it works fine, also when I was testing with both StarterCharacter, I uploaded the game and allowed https request while testing with both, through.
-mari again
You replaced my blank StarterCharacter with yours? The Shirt instance in yours is named “Pants”, and the Pants is named “Shirt”. Thats why the error says trying to find PantsTemplate in Shirt… xD
Shift the names of your Pants and Shirt first
fixed that name issues through, but now when I join the game my character is wearing default clothes for brief second and gets n@aked, and buttons still not work and shows “HTTP 403 Forbidden” error even through I have HTTP allowed in my game,
also here is model of that StarterCharacter I’m using mainly, it’s R6 and have worn Shirt named Shirt and Pants named Pants. here is the model, and thank you very much for helping me out by ton.
AshiStarterCharacterModel.rbxm (10.6 KB)
The player character being naked means that the String placed in the ShirtTemplate is not a valid URL. You should provide a string like this: "http://www.roblox.com/asset/?id=6680877684"
so the Shirt or Pants be loaded correctly.
Probably the data in the datastore has been saved as a number and not as a string URL.
Add prints to show what DataStore has when player joins to debug, or check the Shirt/Pants properties in explorer too.
A string will be stored in a StringValue inside the Player, the script I already gave you called “SavingScript” its already handling that:
- When player joins creates a Folder called MyCloths and placed in Player along with StringValues called ShirtVal and PantsVal to store the cloths the player is using.
- Read the DSS and perform different tasks depending on new player or rejoined
- And listening when the Shirt or Pants has been changed by Server to rewrite the String values inside MyCloths folder.
- When player leaves, takes the values inside MyCloths folder and save them into DSS
You gotta make sure that you are changing the Shirt and Pants template with a button or something on ServerSide so my savingScript read that and when player leaves save it.
And make sure you are providing a correct URL string to be placed in the Shirt and Pants template.
If you have the Roblox Catalog IDs of the Shirts and Pants you wanna use, you can get the right URL string with this, just replace the IDs:
local ShirtURL = game:GetService("InsertService"):LoadAsset(6680877688).Shirt.ShirtTemplate
local PantsURL = game:GetService("InsertService"):LoadAsset(6314613214).Pants.PantsTemplate
To make things easier, just place this folder in Workspace. Play test, click some buttons those will change your shirt and pants, then leave test to save the DataStore, join again to verify it was saved.
Then look for the script inside the folder and replace the IDs with the ones you collected from Roblox Catalog:
ClothBTNs.rbxm (4.3 KB)
hello there, your script kinda helped me with that but when I changed the IDs in the script, now whole thing broken, and I even used an datastore editor but I suck at using that, also I want to use these codes listed below in that clotheBTNs folder script, here I list them below.
Shirts= 7843411811, 9056088978, 8224770109, 7307508033
pants= 6594989145, 10023059908, 5814743514, 6594989145
sorry for this much of inconvinces, you are great, anyway. I will also show you the footage of me click the BTN parts but it does not work and nor doesn’t print anythings in output, it would be very awesome if you could help me with it, thank you so much.
(I was taking two hours to respond due to eating dinner in outside.)
-Mari
Its broken cause those are not Catalog IDs, those are Library IDs, the direct texture ID.
In the example I gave you I was directly copying the ID from Catalog, then by script collecting the texture ID. In your case you dont need to collect the texture ID from the Catalog ID, cause you already have the texture ID, replace ClothBTNScript with this:
local InsertService = game:GetService("InsertService")
--local ShirtsIDs = {6680877688, 7713626261, 11612658975, 6780970545}
--local PantsIDs = {6314613214, 6752704115, 5053949817, 11679597207}
local URLstart = "http://www.roblox.com/asset/?id="
local ShirtsIDs = {7843411811, 9056088978, 8224770109, 7307508033}
local PantsIDs = {6594989145, 10023059908, 5814743514, 6594989145}
for i, btn in pairs(game.Workspace:WaitForChild("ClothsBTNs"):WaitForChild("Shirts"):GetChildren()) do
--local ShirtURL = InsertService:LoadAsset(ShirtsIDs[i]).Shirt.ShirtTemplate
btn:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
--player.Character.Shirt.ShirtTemplate = ShirtURL
player.Character.Shirt.ShirtTemplate = URLstart..tostring(ShirtsIDs[i])
end)
end
for i, btn in pairs(game.Workspace:WaitForChild("ClothsBTNs"):WaitForChild("Pants"):GetChildren()) do
--local PantsURL = InsertService:LoadAsset(PantsIDs[i]).Pants.PantsTemplate
btn:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
--player.Character.Pants.PantsTemplate = PantsURL
player.Character.Pants.PantsTemplate = URLstart..tostring(PantsIDs[i])
end)
end
I disabled all lines in the script that search the Library ID by using the Catalog ID. And now its directly using the Library IDs that you have.
Testing your IDs video:
hey thank you so much for you help in total! the things finally come into my hand and there is four pairs of buttons that can change the clothings in my game and saves it! let me show you the footage of that.
however, could you please tell me how to make more pairs of buttons like that? then I may gladly gift you with Solutions, and you can finally move on for others help, if I stumble upon problem with this thing, I may call you for need. thank you.
-very happy mari
Its looking good! Good job at ordering them, cause the example I provided its kinda hardcoded and unordered, and Im wodering how you did ordered each button to be in front of the Item/Cloths that belongs.
Did you edited the order of these arrays?:
local ShirtsIDs = {7843411811, 9056088978, 8224770109, 7307508033}
local PantsIDs = {6594989145, 10023059908, 5814743514, 6594989145}
Or are you using a different script to give functions to the ClickDectectors on those parts?
Im asking that, because the way to add more buttons depends on how you are giving the functions to the buttons.
The example I gave its hardcoded, and its only iterating the parts in a folder in workspace. And using the number of the iteration to take a value from a table.
You would need to add a new texture ID into this table: local ShirtsIDs
and
add a new part with a ClickDetector in the Workspace folder ClothsBTNs > Shirts or Pants.
The entire approach was only for testing, it can be improved a lot, its just about step by step
Saving every time the player dies isn’t that bad unless you have 59 different obstacles.
hello there, I’m sorry for asking for bit more when it’s solved but,
can we make it so we can add some value into respective parts in BTN files and script reads what value is inside the clicked part and use that value number for make it into roblox clothing texture id and apply it to player and then saves it? sorry for being late for 3 days but I may ask you about this before it closes, thank you peashie.
-mari
Hey there!
Sure, place a IntValue into each button in the folder, and name it as ID
, in the IntValue Value property place the id number 1564561561
(I mean your IDs), then iterate them with a code like this; should be 2 folders, you know shirts and pants are 2 different folders.
local URLstart = "http://www.roblox.com/asset/?id="
for i, btn in pairs(game.Workspace:WaitForChild("ClothsBTNs"):WaitForChild("Shirts"):GetChildren()) do
btn:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
player.Character.Shirt.ShirtTemplate = URLstart..tostring(btn.ID.Value)
end)
end
for i, btn in pairs(game.Workspace:WaitForChild("ClothsBTNs"):WaitForChild("Pants"):GetChildren()) do
btn:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
player.Character.Pants.PantsTemplate = URLstart..tostring(btn.ID.Value)
end)
end
It will check each one of those “button” parts, and use the IntValue called ID inside the part, to use it as the URL that will be used to place the texture.
hey there, the things you have suggested to me have worked very well and I love that, thanks for helping me out with making saving clothing system by this far, I also thank you for friending me on roblox through
hope you will have more amazing days after this, I salute you.
also here is footage of saving clothing system working well in my game, it could be all possible because of you!
I gave you another solution to your recent respond(even through previous solution moved into your recent respond) and hearted your reply message, you are the best hero. thank you.
-happy mari
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.