Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to save Character parts and textures like clothing into a data store?

Asked by
acuaro 29
4 years ago

So, in my game, I have a part where the player custom creates their character before starting the game. I need a way to store this into a data store because there is a "Load option" .I need the data store so that you can click the load button and get you're currency and character the same as when you left. Here are the options of the character & their code (just incase you need it!)

** Faces**

game.ReplicatedStorage.Events.FaceEvent4.OnServerEvent:Connect(function(plr)
    local char = plr.Character

    if char:findFirstChild("Humanoid") then
        char.Head.face.Texture = "http://www.roblox.com/asset/?id=324583433"
    end
end)

Clothing (both pants & shirts!)

game.ReplicatedStorage.Events.ShirtEvent2.OnServerEvent:Connect(function(plr)
    local char = plr.Character -- Getting Character 

    char:findFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=3605712285" -- Getting Shirt Template ID
end)

** Skin Color**

game.ReplicatedStorage.Events.ColorEvent2.OnServerEvent:Connect(function(plr) -- getting on server event (ColorEvent1, ColorEvent 2 ect)
    local button = game.StarterGui.CustomizeChar.Frame1.SkinColor2  -- Getting skin changing button

    local q = BrickColor.new("Brown") -- Color Of Skin
    local char = plr.Character

    char.Head.BrickColor = q                -- Getting each part of the body to chnage to q (Desierd Color of Skin)
    char.UpperTorso.BrickColor = q
    char.LowerTorso.BrickColor = q
    char["RightLowerArm"].BrickColor = q
    char["LeftLowerArm"].BrickColor = q
    char["RightUpperArm"].BrickColor = q
    char["LeftUpperArm"].BrickColor = q
    char["LeftLowerLeg"].BrickColor = q
    char["RightLowerLeg"].BrickColor = q
    char["RightUpperLeg"].BrickColor = q
    char["LeftUpperLeg"].BrickColor = q
    char["RightFoot"].BrickColor = q
    char["LeftFoot"].BrickColor = q
    char["RightHand"].BrickColor = q
    char["LeftHand"].BrickColor = q

end)

** & Finally Hair **

game.ReplicatedStorage.Events.HairEvent1.OnServerEvent:Connect(function(plr)
    local Storage = game.ReplicatedStorage.Hair.Hair1
    local char = plr.Character -- Getting Character

    if char:findFirstChild("Humanoid") then
        local Folder = char.Head.Hair -- Getting Hair Folder

        Folder:ClearAllChildren()


        local Head = char.Head -- Getting Head
        local New_Hair = Storage:Clone() -- Cloning Hair

        New_Hair.Parent = Folder  -- 115 through 121 is welding the hair to the body
        New_Hair.Position = Head.Position
        local Weld = Instance.new("Weld")
        Weld.Parent = New_Hair
        Weld.Part0,Weld.Part1 = Head, New_Hair
        Weld.C0 = CFrame.new(0,0.6,0)
        Weld.C1 = Head.HairAttachment.CFrame
    end

(I put the code just incase you needed it)

I looked every where and can't find a way to save these into a number or something and then save that in the data store. If you could help figure this out that would be really helpful. All I need is just a way to store this into a data store. If you have any suggestions on changing the code for one of the customizations that would also be helpful!

Thank you in advance

acuaro

1 answer

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago
Edited 4 years ago

I believe that you can save it straight in there, and if not, put it in an object value. I know that it's possible as I've saved weapons like that. For SkinColor, just save the color in a Color3 value. You can save it all in a dictionary like so

local saves = {
    'Hair' = --get hair instance here
    'SkinColor' = --get color3 value of skin
    etc...
}

--perform save actions

I hope this helps, if you have any questions or problems involving my answer, just comment below.

0
Thank you a lot, and I tested the skin color & it works. The only thing is I don't really under stand by what you mean of "get hair instance". If you could help, Thanks. acuaro 29 — 4y
0
I don't really have much experience with hair and stuff, but I believe it has it's own instance, or object. So in other words, get the hair object, that's how the hair works, correct? sheepposu 561 — 4y
0
Oh Yeah :P, thats how it works. I'll go try it out. I'm so . dumb :P. Thank you. acuaro 29 — 4y
0
Uh oh its not working, here is the code -- local save = { "Hair" = char.Head.Hair:GetChildren() }. When I hover over "Hair" it says "Expected Name, Got a Complex Expression" acuaro 29 — 4y
View all comments (8 more)
0
I forgot, you may need to put brackets around the key of the dictionary, so it would look like this. local saves = { ['Hair'] = char.Head.Hair:GetChildren() } sheepposu 561 — 4y
0
Hopefully that works sheepposu 561 — 4y
0
I'll test it out acuaro 29 — 4y
0
I'm really sorry for disturbing you more, but that dosen't seem to be working either. I tried to print the Hair (The name of the hair) but the error just said "line 9" which was the line with ['Hair'] = blah blah blah. acuaro 29 — 4y
0
Sorry for the late reply. char.Head:GetChildren() returns an array of the children of Head. idk much about the hair, but why do you need all children of the characters head? sheepposu 561 — 4y
0
Because I'm not sure what hair the player is wearing right now acuaro 29 — 4y
0
I think I understand now, perhaps it would be better to do this then. char.Head:GetChildren()[1] to indicate that you want the first (and only?) value. sheepposu 561 — 4y
0
Yes, That worked! Thank you acuaro 29 — 4y
Ad

Answer this question