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

How Can I Save/Load Humanoid MaxHealth And WalkSpeed?

Asked by 5 years ago

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

0
lemme write you an answer User#23252 26 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

Ad

Answer this question