When I try to save the player.Speed value (the value representing their walkspeed) it didn't save, and I was using the same thing before but it didn't work, it also says that speed is not a valid member of the player. I created the Speed value in a separate script. Datastore script:
local datastoreserv = game:GetService("DataStoreService")
local myData = datastoreserv:GetDataStore("NewData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local Cash = Instance.new("IntValue")
Cash.Parent = leaderstats
Cash.Name = 'Cash'
local codesRedeemed = Instance.new("BoolValue")
codesRedeemed.Name = "CodeRedeemed"
codesRedeemed.Value = false
codesRedeemed.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
local speed = player.Speed
local key = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
d`ata = myData:GetAsync(key)
end)
if success then
if data then
Cash.Value = data.Cash
points.Value = data.Points
speed.Value = data.Speed
end
else
warn("ERROR")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = "Player_"..player.UserId
local data = {
Cash = player.leaderstats.Cash.Value;
Points = player.leaderstats.Points.Value;
Speed = player.Speed.Value;
}
local success, errormessage = pcall(function()
myData:SetAsync(key, data)
end)
if success and data then
print("Data Saved successfully")
else
warn(errormessage)
end
local Players = game.Players
end)
script used to create the value:
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local speed = Instance.new("IntValue")
speed.Parent = player
speed.Name = "Speed"
speed.Value = 16
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").WalkSpeed = player.Speed.Value
end)
end) --This is a script that loads your walkspeed on respawn
