Hello developer, I have created a game where you can dress yourself and then play with the characters in the game. However, it is annoying that the players have to put their avatars together again and again. So I wanted to ask how it is possible to save designed player avatars (the player can put the outfit back on after clicking on an image button in the save GUI, the designed character can be seen on the GUI [similar to catalog avatar])
Can someone explain to me how this works?
Basically I’d suggest, looping through all accessories and saving them to a table, a long with shirts, and pants, then save the body color, and what not, all of this would be saved in a table, which would then be saved in a datastore so you can access it whenever needed, it would prob look something like this:
local info = {
Accessories = {Hat, Bean, Feed me, etc}
FaceId = "FACEIDHERE"
Clothing = {Shirt, Pants, Etc}
BodyColors = {Head = color,Torso = Color, etc.}
}
Now sense you cant save objects, you would just get the ID of every accessory, and save that
To load in any items you take their ID and use InsertService:LoadAsset()
Ok, thankyou for the answer, do you have any idear how i can make that the Player Avatar image is ON a GUI Button?
The documentation should show you how to do it. I’m on mobile rn so I can’t show example code
If you need to display an in-game character model, you should use a ViewportFrame. However, if you’re looking to show just the head image of your avatar, I’ve provided a solution below that I used for my intro:
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local PlayerUserID = 4170063920
local content, isReady = Players:GetUserThumbnailAsync(PlayerUserID, thumbType, thumbSize)
if isReady then
Background.Person1.Image = (isReady and content)
end
Ok i have 2 questions
Will the player BE able to save more than 1 character with the Script (i would Like to make the Images in to a UIGridLayout so the Player can choose between His saved Outfits)?
- IT only Show the Player with the ID:
4170063920
i have changed it, but am Not Sure If It IS corectly and working, and i cant try it yet cus i am ON mobile right now,(i am Not the best scripter, so could anybody Tell me?)
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local thumbType = Enum.ThumbnailType.Avatar
local thumbSize = Enum.ThumbnailSize.Size420x420
local PlayerUserID = localPlayer.UserId
local content, isReady = Players:GetUserThumbnailAsync(PlayerUserID, thumbType, thumbSize)
if isReady then
Background.Person1.Image = content
end
Hmm well when you save data to a data store what you could do is this:
local characters = {}
-- now all you need to do is put the characters info in the table, like so
local character = {} -- pretend this is the info for a character
tab.e.insert(characters,character) -- inserts character into the characters table
datastore:SetAsync(key,characters)
Wait what are you trying to do with this? A little context might help on what youre going for! :3
I want to use this script to allow players who have changed their avatar to save it, so that the next time they join the game they don’t have to create this avatar again but can simply use it.
an example image (sorry for the poor quality)
The Player images, will be in the starterGUI in a UIGridLayout
so the Images that get Created by a Script will be in a Serie
THANKYOU FOR HELPING ME ALL THE TIME!!
⎛⎝ ≽ > ⩊ < ≼ ⎠⎞
Hmm ok heres what I think ya should do:
-
- Save the current character, this is done by well uh, button press ig.
-- this would be a local script somewhere
local saveCharB = ButtonHere
local saveEvent = RemoteEventHere
saveCharB.Activated:Connect(function()
saveEvent:FireServer()
end
Next we need to save the characters, so something like this:
-- this would prob be a server script
local data = {}
local datastore = game:GetService('DataStoreService'):GetDataStore('PlayerCharacters')
local saveEvent = REMOTE_EVENT
game.Players.PlayerAdded:Connect(function(player)
local playerCharacters = datastore:GetAsync(player.UserId) -- this is where youd use datastores to get any saved data
data[player.UserId] = playerCharacters
end
game.Players.PlayerRemoving:Connect(function(player)
local playerData = data[player.UserId]
datastore:SetAsync(player.UserId,playerData)
end
saveEvent.OnServerEvent:Connect(function(plr)
local currentChar = INFO_FOR_THE_CURRENT_CHARACTER
table.Insert(data[plr.UserId],currentChar) -- inserts the current characters info into it
end
-- now lets say you want to give the client this info, what we could do is this
local getInfoEvent = REMOTE_FUNCTION
getInfoEvent.OnServerInvoke = function(plr)
local plrData = data[plr.UserId]
return plrData
end
-- so then on a local script, what we could do is this:
local getInfoEvent = REMOTE_FUNCTION
local characters = getInfoEvent:InvokeServer() -- this would give you the info
Ofc this is just a base to help get you started, you would obviously swap out some of the variables with actual things, like an remote event and function.
I would also looking into datastores for saving data if you dont know already how to, just to give you some more info. Theres a bunch of other stuff you could do like using pcalls so things dont error and break everything, but I dont feel like writing a whole essay so this will have to do.
This may take a while to perfect but im sure you can pull it off! If you need any help feel free to ask me! Best of luck~
~ Frodev
The data leak here will be astronomical
Your code should work though in theory
I wrote this without any syntax so I couldnt be bothered to use UpdateAsync and what not, you totally should though @killerrdrohne , I just didnt feel like doing it lol.