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

Making a DataStore for Humanoid?

Asked by 6 years ago

Im trying to save the size of the players BodyWidthScale, BodyHeightScale, and BodyDepthScale. I want the values to load when a player resets, dies, or rejoines the game. Here's the script I have that doesn't work:

script.Parent= nil

local minute= (10)

function save(player)
    local StatToSave = player.Chracter.Humanoid
    ---------
    local datastore = game:GetService('DataStoreService'):GetDataStore(player.Name..'Stats')
    local statstorage = StatToSave:GetChildren()
        for i =  1, #statstorage do
            datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
        end
print(player.Name..' size autosaved')
end


game.Players.LocalPlayer.CharacterAdded:connect(function()
    local player = game.Players.LocalPlayer
    local StatToSave = player.Chracter.Humanoid:GetChildren()
local led= script:findFirstChild(StatToSave)
repeat wait() until led~= nil
local BWS = player.Character:findFirstChild("Humanoid").BodyWidthScale
BWS:Delete()

local BDS = player.Character:findFirstChild("Humanoid").BodyDepthScale
BDS:Delete()

local BHS = player.Character:findFirstChild("Humanoid").BodyHeightScale
BHS:Delete()

led:Clone().Parent= player.Character.Humanoid
    local datastore = game:GetService('DataStoreService'):GetDataStore(player.Name..'Stats')
        player.Character:FindFirstChild("Humanoid"):GetChildren()   wait()
        local stats = player.Character:FindFirstChild("Humanoid"):GetChildren()
        for i = 1, #stats do            
            stats[i].Value = datastore:GetAsync(stats[i].Name)
        end
if player.Name:match("Guest") then
print(player.Name..' has joined')
else end
        while game.Players:findFirstChild(player.Name) do
            save(player)
            wait(minute)
        end
end)

game.Players.PlayerRemoving:connect(function(player)
    local datastore = game:GetService('DataStoreService'):GetDataStore(player.Name..'Stats')
    local statstorage = player.Character:findFirstChild("Humanoid"):GetChildren()
        for i =  1, #statstorage do
            datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
        end
            print(player.Name..' Size saved succesfully! ') 
end)
1
Please provide more detail: Is there an error message? Is your autosave working/message printing? What data are you trying to store: Is it a number, string? And what type of data is statstorage? whenallthepigsfly 541 — 6y

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

There is nothing visibly wrong with this script. You should also not create a new store with GetDataStore(player.Name..'Stats') for every single player. Here we go.. The people saying I'm wrong, the very people who said this was correct. You may also want to consider using a table to store the data of the player, to save datastore use. You are limited with certain rates/minute. By the way, unless you enabled api use, this won't work in studio.

0
api is enabled taunter165 30 — 6y
0
In the place config? game is different from place. H4X0MSYT 536 — 6y
0
both, i havealeaderstatssave too andd it works taunter165 30 — 6y
Ad

Answer this question