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

How Can I Save/Load Humanoid MaxHealth And WalkSpeed?

Im Making a Game that has Speed Stats and Defense Stats, But How can i Save And Load it? Please help

1 comment

0

lemme write you an answer

1 answer

you could use DataStore Service; like this

local dataName = "WalkSpeed_In_ThisGreatGameLovedByBillionsOfEarthie's"  -- choose a unique name that cannot easilly be guessed

local data_store = game:GetService("DataStoreService):GetDataStore(dataName)
local defaultSpeed = 16
local=secondPartOfAccessKey=player.Name.."'sKeyForDataAccessInThisCoolGamemwahaha"

game.Players.PlayerAdded:Connect(function(player)

	local dataAccess_key = player.Name..secondPartOfAccessKey -- again for layer of security, choose unguessable name

	local savedData ;

	local yay,nay = pcall(function()
		savedData = data_store:GetAsync(dataAccess_key);
	end

	if savedData and yay then
		print("data was found")
		player.Character.Humanoid.WalkSpeed = savedData
	else
		print("new player to game")
		player.Character.Humanoid.WalkSpeed=defaultSpeed
	end
	
end









game.Players.PlayerRemoving:Connect(function(player)
	local dataAccess_key = player.Name..secondPartOfAccessKey
	local current_speed = player.Character.Humanoid.WalkSpeed
	
	data_store:SetAsync(dataAccess_key,current_speed)
end)

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