You’re probably not getting this error because you’re pressing “Stop” in the test menu, which means PlayerRemoving is inconsistent as the script doesn’t have enough time to fully run before the play session is shut down.
But even in the real game your speed doesn’t save when you leave after buying speed upgrade. Here Try: Clicking MONSTERS! 👹 [V1.03] - Roblox It saves everything but your speed.
Well yes, my theory is that the error message will persist in a live game as well as it can’t actually find the Humanoid. The only reason you’re not getting the error message is because I assume PlayerRemoving doesn’t have enough time to fully fire.
Is everything else in the character, or is it in the player?
This would most likely line up with my theory then, give this a try and let me know if it changes.
Also I would highly recommend not using the following code for an actual live game, if you plan on converting this to live game code try to add a pcall for the :GetAsync and try to reduce the potential memory leaks that come along with this.
local DSS = game:GetService("DataStoreService")
local PlayerSave = DSS:GetDataStore("Walk")
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local WalkSpeed = PlayerSave:GetAsync("WalkSpeed-"..plr.UserId)
if WalkSpeed == nil then
WalkSpeed = 16
end
local hum = char:WaitForChild("Humanoid")
local NewValue = Instance.new("IntValue")
NewValue.Name = "Walkspeed"
NewValue.Value = WalkSpeed
hum.WalkSpeed = WalkSpeed
NewValue.Parent = plr
hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
NewValue.Value = hum.WalkSpeed
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
PlayerSave:SetAsync("WalkSpeed-"..plr.UserId,plr.Walkspeed.Value)
end)
Ight, lets do this :
[Similar to @alphadoggy111 's solution, but with a pcall]
local DataStore = game:GetService("DataStoreService"):GetDataStore("SpeedData")
game.Players.PlayerAdded:Connect(function(Player)
local speedData = DataStore:GetAsync("WalkSpeed-"..Player.UserId)
local SpeedValue = Instance.new("IntValue",Player)
SpeedValue.Name = "PlayerSpeed"
local success,error = pcall(function()
SpeedValue.Value = speedData
end)
if error then
SpeedValue.Value = 16
end
Player.CharacterAdded:Connect(function(Char)
local hum = Char:WaitForChild("Humanoid")
if hum then
hum.WalkSpeed = SpeedValue.Value
SpeedValue.Changed:Connect(function()
hum.WalkSpeed = SpeedValue.Value
end)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local success,error = pcall(function()
DataStore:SetAsync("WalkSpeed-"..Player.UserId,Player.PlayerSpeed.Value)
end)
if not success then
warn(error)
else
print(success)
end
end)
local DataStore = game:GetService("DataStoreService"):GetDataStore("SpeedData")
game.Players.PlayerAdded:Connect(function(Player)
local speedData = DataStore:GetAsync("WalkSpeed-"..Player.UserId)
local SpeedValue = Instance.new("IntValue",Player)
SpeedValue.Name = "PlayerSpeed"
local success,error = pcall(function()
SpeedValue.Value = speedData
end)
if error then
SpeedValue.Value = 16
end
Player.CharacterAdded:Connect(function(Char)
local hum = Char:WaitForChild("Humanoid")
if hum then
hum.WalkSpeed = SpeedValue.Value
SpeedValue.Changed:Connect(function()
hum.WalkSpeed = SpeedValue.Value
end)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local success,error = pcall(function()
DataStore:SetAsync("WalkSpeed-"..Player.UserId,Player.PlayerSpeed.Value)
end)
if not success then
warn(error)
else
print(success)
end
end)
local DataStoreService = game:GetService("DataStoreService")
local PlayerSave = DataStoreService:GetDataStore("PlayerSave")
local RemoteEvents = game.ReplicatedStorage.RemoteEvents
local SpeedMultiplier = RemoteEvents.SpeedMultiplier
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
task.wait()
local PlayerSpeed = Character.Humanoid.WalkSpeed
local leaderstats = Player.leaderstats
local Clicks = leaderstats.Clicks
local BaseStats = Player.BaseStats
local Speed = BaseStats.Speed
local ClicksData,WalkSpeed,Restarts,ButtonPresses
local success, errormessage = pcall(function()
ClicksData = PlayerSave:GetAsync("Clicks-"..Player.UserId)
Restarts = PlayerSave:GetAsync("Restarts-"..Player.UserId)
ButtonPresses = PlayerSave:GetAsync("ButtonPresses-"..Player.UserId)
WalkSpeed = PlayerSave:GetAsync("WalkSpeed-"..Player.UserId)
end)
if success then
if ClicksData then
Player.leaderstats.Clicks.Value = ClicksData
else
end
if success then
warn(errormessage)
if WalkSpeed == nil then
Player.Character.Humanoid.WalkSpeed = 16
print("This is DataStore WalkSpeed "..WalkSpeed)
else
Player.Character.Humanoid.WalkSpeed = WalkSpeed
local NewValue = Instance.new("IntValue")
NewValue.Name = "Walkspeed"
NewValue.Value = WalkSpeed
Character.Humanoid.WalkSpeed = WalkSpeed
NewValue.Parent = Player
Character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
NewValue.Value = Character.Humanoid.WalkSpeed
end)
end
if success then
if ButtonPresses then
Player.BaseStats.ButtonPresses = ButtonPresses
end
if success then
if Restarts then
Player.leaderstats.Restarts.Value = Restarts
else
Player.leaderstats.Restarts.Value = 1
end
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local success, errormessage = pcall(function()
game:BindToClose(function()
PlayerSave:SetAsync("Clicks-"..Player.UserId,Player.leaderstats.Clicks.Value)
PlayerSave:SetAsync("Restarts-"..Player.UserId,Player.leaderstats.Restarts.Value)
warn("Binded to close. I saved everything!")
PlayerSave:SetAsync("WalkSpeed-"..Player.UserId,Player.Character.Humanoid.WalkSpeed)
PlayerSave:SetAsync("ButtonPresses-"..Player.UserId,Player.BaseStats.ButtonPresses.Value)
end)
end)
end)
end)
Yeah, I recommend having a single datastore named something like “MainData” and save it as a table with the real data inside like WalkSpeed and ClicksData.