Datasave walkspeed of 16 applies to humanoid as 1.6 instead

So here I have a data save system saving different stats. the focus is the “MovementSpeed” stat. For some odd reason, regardless of the stats.movementspeed.value printing as “16”, when the value is actually applied it sets the humanoid.walkspeed to “1.6” instead. I have 0 clue on how this is even possible.

local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("LeaderStatSave")

local D_Dmg = script:GetAttribute("DefaultDmg")
local D_DmgCooldown = script:GetAttribute("DefaultDmgCooldown")
local D_Health = script:GetAttribute("DefaultHealth")
local D_WalkSpeed = script:GetAttribute("DefaultWalkSpeed") -- is 16
local D_Size = script:GetAttribute("DefaultSize")
local D_ExpRequirement = script:GetAttribute("DefaultExpRequirement")
local ExpMultiplier = script:GetAttribute("ExpReqMultiplierPerLvl")

local function UpdateLevelStats(Plr, Exp, Level, EarnedExp)
	repeat task.wait() until Plr.Character
	warn("check stats")
	local PlrStats = Plr.Character.Stats
	local ExpReq = Plr.Character.Stats.ExpRequirement
	local Exp = Plr.Character.Stats.Exp
	
	if Level <= 200 then
		if Exp.Value >= ExpReq.Value then
			print("level up")
			Plr.leaderstats.Level.Value += 1
			ExpReq.Value *= 1.1 --exp requirement
			Plr.Character:ScaleTo(Plr.Character:GetScale() + 0.025) -- size
			Plr.Character.Stats.ScaleSize.Value += 0.025 -- size_stat
			PlrStats.Dmg.Value += 0.5 -- dmg
			PlrStats.DmgCooldown.Value -= 0.25
			Plr.Character.Humanoid.MaxHealth += 1 ----------------------------- MHealth
			Plr.Character.Humanoid.Health = Plr.Character.Humanoid.MaxHealth -- Health
			Plr.Character.Stats.MaxHealth.Value = Plr.Character.Humanoid.MaxHealth -- MHealth_Stat
			Plr.Character.Humanoid.WalkSpeed += 0.25 -- WalkSpeed
			Plr.Character.Stats.MovementSpeed.Value += 0.25 -- WalkSpeed_Stat
			--if Exp.Value >= ExpReq.Value then -- incase more than one lvl is needed
				--UpdateLevelStats()
			--end
		end
	end
end

local function ApplyData(Plr) -- PROBLEM LOCATED HERE!!
	Plr.Character.Humanoid.Health = Plr.Character.Stats.MaxHealth.Value
	Plr.Character.Humanoid.MaxHealth = Plr.Character.Stats.MaxHealth.Value
	print(Plr.Character.Stats.MovementSpeed) -- indeed prints 16
	Plr.Character.Humanoid.WalkSpeed = Plr.Character.Stats.MovementSpeed.Value --confirmed to be 16. however 1.6 is set to Humanoid.WalkSpeed. why???
	Plr.Character:ScaleTo(Plr.Character.Stats.ScaleSize.Value)
end

game.Players.PlayerAdded:connect(function(player)
	wait(2)
	local leaderstats = Instance.new("Folder",player)
	local Exp = Instance.new("NumberValue",leaderstats)
	local Level = Instance.new("NumberValue",leaderstats)
	local playerData = DataStore:GetAsync(player.UserId)

	leaderstats.Name = "leaderstats"
	Exp.Name = "Exp"
	Level.Name = "Level"
	
	if playerData then --set stats
		print("loading plr data")
		Exp.Value = playerData.exp or 0
		player.Character.Stats.Exp.Value = playerData.exp
		Level.Value = playerData.level or 1
		player.Character.Stats.ExpRequirement.Value = playerData.requiredExp
		player.Character.Stats.Dmg.Value = playerData.dmg
		player.Character.Stats.DmgCooldown.Value = playerData.dmgCooldown
		player.Character.Stats.MaxHealth.Value = playerData.maxHealth
		player.Character.Stats.MovementSpeed.Value = playerData.movementSpeed
		player.Character.Stats.ScaleSize.Value = playerData.scale
		print("plr data loaded")
	else
		print("new player")
		Exp.Value = 0
		player.Character.Stats.Exp.Value = 0
		Level.Value = 1
		player.Character.Stats.ExpRequirement.Value = D_ExpRequirement
		player.Character.Stats.Dmg.Value = D_Dmg
		player.Character.Stats.DmgCooldown.Value = D_DmgCooldown
		player.Character.Stats.MaxHealth.Value = D_Health
		player.Character.Stats.MovementSpeed.Value = D_WalkSpeed
		player.Character.Stats.ScaleSize.Value = D_Size
		print("default data loaded")
	end
	
	local Data = {
		["exp"] = Exp.Value, 
		["level"] = Level.Value, 
		["requiredExp"] = player.Character.Stats.ExpRequirement.Value,
		["dmg"] = player.Character.Stats.Dmg.Value,
		["dmgCooldown"] = player.Character.Stats.DmgCooldown.Value,
		["maxHealth"] = player.Character.Stats.MaxHealth.Value,
		["movementSpeed"] = player.Character.Stats.MovementSpeed.Value,
		["scale"] = player.Character:GetScale()}
	Exp.Changed:connect(function()
		local NewData = {
			["exp"] = player.leaderstats.Exp.Value, 
			["level"] = player.leaderstats.Level.Value, 
			['requiredExp'] = player.Character.Stats.ExpRequirement.Value,
			["dmg"] = player.Character.Stats.Dmg.Value,
			["dmgCooldown"] = player.Character.Stats.DmgCooldown.Value,
			["maxHealth"] = player.Character.Stats.MaxHealth.Value,
			["movementSpeed"] = player.Character.Stats.MovementSpeed.Value,
			["scale"] = player.Character:GetScale()}
		DataStore:SetAsync(player.UserId, NewData)
		UpdateLevelStats(player, Exp.Value, Level.Value, true)
	end)
	ApplyData(player)
	UpdateLevelStats(player, Exp.Value, Level.Value, true)
	print(`EXP: {Data.exp} || LEVEL: {Level.Value} || ReqExp: {player.Character.Stats.ExpRequirement.Value}`)
end)
1 Like

Hey there, your code is a bit… confusing.
Nonetheless, can’t you just multiply the result by 10?

1 Like

If this doesn’t work, I think the problem is that, on the previous playtests, you accidentally changed the walkspeed to 1.6, so, when you start the playtest again, the walkspeed will be saved.
So change the datastore name to another one:

If that doesn’t work, I think we can have a bit more of common sense. If the walkspeed depends on the XP or Level, why don’t you just save the level, and then do some math to see what the WalkSpeed of the player will be. No need to save it in the DataStores, because what is the most important is the XP

would clearing data using data manager in experience settings also work? instead of creating a new datastore

Wait, you can clear data from DataStore? What the heck, I didn’t know that.

yeah lol visit experience settings then scroll down to data manager. there u can see data u saved under your datastore name

anyways im gonna try this

Oh, never thought about that. So that’s what the Data Manager was for…

i suppose you are right about walkspeed not necessarily needing to be saved so i’ll redo my script a bit to find the correct walkspeed to give based off the level and walkspeed per level. although this doesnt solve this mystery, it is a work around

also with data being cleared, the walkspeed remains 16 applied as 1.6

Weird. Or it is Roblox’s fault (very unlikely), or it’s some logic that it is wrong in your code that I can’t find.

local function ApplyData(Plr) -- PROBLEM LOCATED HERE!!
	Plr.Character.Humanoid.Health = Plr.Character.Stats.MaxHealth.Value
	Plr.Character.Humanoid.MaxHealth = Plr.Character.Stats.MaxHealth.Value
	print(Plr.Character.Stats.MovementSpeed) -- indeed prints 16
	Plr.Character.Humanoid.WalkSpeed = Plr.Character.Stats.MovementSpeed.Value --confirmed to be 16. however 1.6 is set to Humanoid.WalkSpeed. why???
	Plr.Character:ScaleTo(Plr.Character.Stats.ScaleSize.Value)
end

ngl, I have no idea whats going on with the rest of the code + I suck at scripting so I might miss something.

However, shouldn’t you be checking if it prints the value correctly like:
print(Plr.Character.Stats.MovementSpeed.Value)
instead of
print(Plr.Character.Stats.MovementSpeed) – indeed prints 16

as you’re setting the walkspeed based on the value of MovementSpeed.

However if its not that which it probably might not be
then it could be the fact you’re setting the character’s walkspeed first, then you’re scaling the character right after.

I don’t exactly know how you handle the scaling of the character but if you want to test if thats the case, just try removing/commenting the line out temporarily.

wow good catch. i’ve never used scaledto() before and upon testing your theory you are correct. for some reason, when scaling a model that is that players character, it edits to walkspeed. to fix this i’ll simply scale first THEN apply the walkspeed. ty!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.