Hello, I am doing a simulator, which is called Speed Simulator. At this point, I need the game to save the humanoid walkspeed, once they leave the game, it’d be boring re-start everytime you rejoin! Is there a script to do it?
Instead add an int value inside your player which stores your speed. So when you leave it can save the data and when you join back the intvalue data will be changed to the players humanoid walkspeed
Watch this tutorial to get a basic idea of how it will be done
local DTS = game:GetService("DataStoreService")
local my_data = DTS:GetOrderedDataStore("Speed") -- Name for Datastore
game.Players.PlayerAdded:Connect(function(plr)
local speed= plr:WaitForChild("Stats"):WaitForChild("Speed")
local data;
local success, errormsg = pcall(function()
data = my_data:GetAsync(plr.UserId)
end)
if success then
speed.Value = data
else
print("Error")
warn(errormsg);
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormsg = pcall(function()
my_data:SetAsync(plr.UserId, plr.leaderstats.Stats.Speed.Value)
end)
if success then
print("Player Data Successfully stored.")
else
print("Error");
warn(errormsg)
end
end)
game.Players.PlayerAdded:Connect(function(plr)
while wait(40) do
local success, errormsg = pcall(function()
my_data:SetAsync(plr.UserId, plr.leaderstats.Stats.Speed.Value)
end)
if success then
print("Player Data Successfully stored.")
else
print("Error");
warn(errormsg)
end
end
end)
This is will save the Intvalue
now set the intvalue to humanoids WalkSpeed.
game.Players.PlayerAdded:Connect(function(plr)
local speed = plr:WaitForChild("Stats"):WaitForChild("Speed").Value
while true do
wait()
plr.Character.Humanoid.WalkSpeed = speed
end
end)
This is a basic example, this might not work properly so you would have to optimize it.
I will explain edit the code with comments to explain what it does later as I am using mobile right now, watch the tutorial I linked to get a better idea.
The stats is not created yet. In fact, you should do CharacterAdded:Wait() to make sure the folder is loaded in. You can also do :WaitForChild('Stats', 100). They work the same. Don’t give up!
CharacterAdded:Wait()
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
-- The script here
end)
end)
:WaitForChild('Stats', 100)
local speed = plr:WaitForChild('Stats', 100):WaitForChild('Speed', 100)
Like @RealJefff2000 said, it is just a small error in a small script. He already provided the solution above. But if you do hire a scripter, make sure it’s voluntary work since it would not be worth it to pay anyone for this heh. Ideally, you could try experimenting around with your script; that way you would learn yourself and would not need help (or less help) from others when you encounter a problem.