i want my datastore script to save the player walkspeed, i have already searched on the devforum and youtube but i couldnt find anything usefull. Can someone help me? This is my datastore script
local dataStore = game:GetService("DataStoreService"):GetDataStore("TestVersion1")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrid = "id_"..plr.UserId
local save1 = plr.leaderstats.Stage
local save2 = plr.leaderstats.Wins
local GetSaved = dataStore:GetAsync(plrid)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberForSaving = {save1.Value,save2.Value}
dataStore:GetAsync(plrid,NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
dataStore:SetAsync("id_"..plr.UserId, {plr.leaderstats.Stage.Value,plr.leaderstats.Wins.Value})
print("Saved data")
end)
tell me if it helps sorry for messy code lol
local dataStore = game:GetService(“DataStoreService”):GetDataStore(“TestVersion1”)
local speedData = game:GetService(“DataStoreService”):GetDataStore(“areyouseriousrightnoew”)
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrid = “id_”…plr.UserId
local save1 = plr.leaderstats.Stage
local save2 = plr.leaderstats.Wins
local speeddata
local key = plr.UserId
pcall(function()
speeddata = speedData:GetAsync(key)
end)
if speeddata ~= nil then
plr.Character.Humanoid.WalkSpeed = speeddata
end
local GetSaved = dataStore:GetAsync(plrid)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberForSaving = {save1.Value,save2.Value}
dataStore:GetAsync(plrid,NumberForSaving)
end
end)
using Humanoid.WalkSpeed but considering it’s saving when the player is leaving it would probably be a good idea to store their walkspeeds somewhere then request walkspeed for that player when they leave.You could use a table to store each players walkspeed and update it every time it changes, then get that value when they leave
just make a intvalue in replicatedstorage for every player that joins and it updates every second
or whenever u want and whenever the player leaves find the players intvalue and save it in the walkspeed data thats how i usually handle with these stuff lol
oh yeah sure
game.Players.PlayerAdded:Connect(function(plr)
local walkspeed = Instance.new(“IntValue”,plr)
walkspeed.Name = “walkspeed”
end)
that should be in serverscript
put this in the player character
game.RunService.HeartBeat:Connect(function()
local plr = game.Players:GetPlayerFromCharacter(script.Parent)
if plr then
if plr.walkspeed then
plr.walkspeed.Value = script.Parent:FindFirstChild(“Humanoid”).WalkSpeed
end
end
end)
remember the both scripts shouldnt be localscripts
and just save the walkspeed if u dont know how the tell me
let me give u updated script (sorry if i sound like chat gpt)
game.[“Run Service”].HeartBeat:Connect(function()
local plr = game.Players:GetPlayerFromCharacter(script.Parent)
if plr then
if plr.walkspeed then
plr.walkspeed.Value = script.Parent:FindFirstChild(“Humanoid”).WalkSpeed
end
end
end)
ok final script this should work
game[“Run Service”].HeartBeat:Connect(function()
local plr = game.Players:GetPlayerFromCharacter(script.Parent)
if plr then
if plr.walkspeed then
plr.walkspeed.Value = script.Parent:FindFirstChild(“Humanoid”).WalkSpeed
end
end
end)