So I have this datastore script, And I am wondering how I would edit it in a way so that Instead of saving the Coins, It saves the walkspeed of the player when leaving the game and loading it when joined
heres the script
--Variables
local DataStoreService = game:GetService('DataStoreService')
local myDataStore = DataStoreService:GetDataStore("myDataStore")
--Imput Moneys
game.Players.PlayerAdded:Connect(function(NewPlayer)
local leaderstats = Instance.new("Folder", NewPlayer)
leaderstats.Name = "leaderstats"
local Coins = Instance.new('NumberValue',leaderstats)
Coins.Name = "Pennys"
local CanGetCookie = Instance.new("BoolValue",NewPlayer)
CanGetCookie.Name = "CanGetCookie"
CanGetCookie.Value = true
--DataStore Script
local player = NewPlayer
local playerUserId = "Player "..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Coins.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player "..player.UserId
local data = player.leaderstats.Pennys.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data Successfully Saved!")
else
print("Something Went Wrong :(")
warn(errormessage)
end
end)
I've tried some stuff. like switching
player.leaderstats.Pennys.Value
to
player.character.Humanoid.WalkSpeed
But it doesnt work Can someone help me out?
