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

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

Asked by
Zrxiis 26
7 years ago

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

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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)
0
You forgot some ends Goulstem 8144 — 7y
0
He never had them and I didn't realize it :) shadownetwork 233 — 7y
0
It's not saving the player's clothes Zrxiis 26 — 7y
0
Nevermind, I typed a part of it wrong Zrxiis 26 — 7y
Ad

Answer this question