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

Making a DataStore for Humanoid?

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 comment

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?

1 answer

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.

3 comments

0

api is enabled

0

In the place config? game is different from place.

0

both, i havealeaderstatssave too andd it works

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