Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I save the players clothes template in a data store?

I tried to make a script for the players clothes but its not working this the script: game.Players.PlayerAdded:connect(function(player)

player.CharacterAdded:connect(function(character)

repeat wait(character:FindFirstChild('Shirt')) until character:FindFirstChild('Shirt') ~= nil

local shirt = character.Shirt

shirt.ShirtTemplate = ds3:GetAsync(player.UserId,shirt.ShirtTemplate)

ds3:SetAsync(player.UserId,shirt.ShirtTemplate)

print("Your shirt has been saved")

repeat wait(character:FindFirstChild('Pants')) until character:FindFirstChild('Pants') ~= nil

local pants = character.Pants

pants.PantsTemplate = ds3:GetAsync(player.UserId,pants.PantsTemplate)

ds3:SetAsync(player.UserId,pants.PantsTemplate)

print("Your pants have been saved")

1 answer

✓ Accepted answer

For starters you should put your R.Lua code in a code block to make it more readable. Also indentation makes it look way better. wait() should only have seconds or nil in it. You never set ds3 so I assume that this is a snip of code and you set it before this snip. GetAsync() only takes one argument not two.

ds3 = ds3 or game:GetService("DataStoreService"):GetDataStore("ClothStorage") --Just making sure ds3 is set. If you already set it above then this line can be removed

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        repeat
            wait()
        until character:FindFirstChild('Shirt') ~= nil

        local shirt = character.Shirt
        local ShirtTemplate = ds3:GetAsync(player.UserId.."Shirt")
        if ShirtTemplate then --If there is a shirt template in the DataStore then
            shirt.ShirtTemplate = ShirtTemplate
        end
        ds3:SetAsync(player.UserId, shirt.ShirtTemplate)
        print("Your shirt has been saved")

        repeat
            wait()
        until character:FindFirstChild('Pants') ~= nil

        local pants = character.Pants
        local PantsTemplate = ds3:GetAsync(player.UserId.."Pants")
        if PantsTemplate then --If there is a pants template in the DataStore then
            pants.PantsTemplate = PantsTemplate
        end
        ds3:SetAsync(player.UserId, pants.PantsTemplate)
        print("Your pants has been saved")
    end)
end)

4 comments

0

You forgot some ends

0

He never had them and I didn't realize it :)

0

It's not saving the player's clothes

0

Nevermind, I typed a part of it wrong

This discussion is preserved as it was. New answers, comments, and votes are closed.