Avatar Scaling issue / data store

Today I was testing my project and I was adding saving player scale. I did a testing server with a few friends and I noticed when they reset, died or left and rejoined, their size would increase dramatically. I’m not sure what is causing this issue, I’ve looked into it and can’t find anything that would increase the size with-out a player activating the tool or the script changing the scale by force.

If you can help then I would appreciate it! :smile:

GIF Example:

DataStore Script (ServerScriptService)
local Data = game:GetService("DataStoreService"):GetDataStore("I")

game:GetService("Players").PlayerAdded:Connect(function(Plr)
    
    --  // Leaderstats
    
    local Stats = Instance.new("Folder", Plr)
    Stats.Name = "leaderstats"
   
    local Strength = Instance.new("IntValue", Stats)
    Strength.Name = "Strength"	
	 
    local Rebirths = Instance.new("IntValue", Stats)
    Rebirths.Name = "Rebirths"

	-- // Alt values
	
	local Scales = Instance.new("Folder", Plr)
    Scales.Name = "Scales"
   
    local BWS = Instance.new("NumberValue", Scales)
    BWS.Name = "BWS"	
	 
    local BHS = Instance.new("NumberValue", Scales)
    BHS.Name = "BHS"

	local BDS = Instance.new("NumberValue", Scales)
    BDS.Name = "BDS"
    
    -- // Loading stuff
    
    local Data1 = Data:GetAsync(Plr.UserId)
    
    if Data1 then
        for i, v in pairs(Stats:GetChildren()) do
            v.Value = Data1[v.Name]
        end
		for i, v in pairs(Scales:GetChildren()) do
            v.Value = Data1[v.Name]
		end
		print(Plr.Name .. "'s data loaded successfully!")
    end
    
	-- // Saving stuff

	spawn(function()
	    while wait(60) do
	        if Stats then
	            local SaveData = {}
	            for i, v in pairs(Stats:GetChildren()) do
	                SaveData[v.Name] = v.Value
	            end
	
				for i, v in pairs(Scales:GetChildren()) do
			       SaveData[v.Name] = v.Value
				end
				
	            Data:SetAsync(Plr.UserId, SaveData)
				print(Plr.Name .. "'s data autosaved successfully!")
	        end
	    end
	end)
	
	Plr.CharacterAdded:Connect(function(Char)
		wait(1)
		repeat wait() until Char:FindFirstChild("Humanoid")
        local Humanoid = Char:WaitForChild("Humanoid")
        local BDS = Humanoid:WaitForChild("BodyDepthScale")
        local BHS = Humanoid:WaitForChild("BodyHeightScale")
        local BWS = Humanoid:WaitForChild("BodyWidthScale")
		if Plr.leaderstats.Strength.Value == 0 then
       		BWS.Value = 0.2
			BDS.Value = 0.2
			BHS.Value = 1
			Plr:FindFirstChild("Scales").BDS.Value = 0.2
			Plr:FindFirstChild("Scales").BHS.Value = 1
			Plr:FindFirstChild("Scales").BWS.Value = 0.2
		else
			BWS.Value = Plr:FindFirstChild("Scales").BWS.Value
			BHS.Value = Plr:FindFirstChild("Scales").BHS.Value
			BDS.Value = Plr:FindFirstChild("Scales").BDS.Value
		end
	end)
end)

game:GetService("Players").PlayerRemoving:Connect(function(Plr)
    local Stats = Plr:FindFirstChild("leaderstats")
	local WeightStats = Plr:FindFirstChild("Scales")
    if Stats then
        local SaveData = {}
        for i, v in pairs(Stats:GetChildren()) do
            SaveData[v.Name] = v.Value
        end
		for i, v in pairs(WeightStats:GetChildren()) do
			if v.ClassName == "NumberValue" then
				SaveData[v.Name] = v.Value
			end
		end
        Data:SetAsync(Plr.UserId, SaveData)
		print(Plr.Name .. "'s data autosaved successfully!")
    end
end)
Local Script (In the tool)
-- // Tom_atoes

local Tool = script.Parent
local Player = game:GetService("Players").LocalPlayer
local Animation = Tool:WaitForChild("Handle").Animation
local Liftable = false
local UIS = game:GetService("UserInputService")
local LastActivated = tick()

function Check()
	if Liftable == true then
		UIS.InputBegan:Connect(function(Input, GPE)
			if GPE then
				return
			end
			
			if Input.KeyCode == Enum.KeyCode.E and Liftable == true then
				if tick() - LastActivated >= 2.5 then
					print("Input Success")
					local AnimPlay = Player.Character:FindFirstChild("Humanoid"):LoadAnimation(Animation)
					AnimPlay:Play()
					Tool.Fire:FireServer(Player, "IsUpdatedByGame")
					LastActivated = tick()
				end
			end
		end)
	end
	
	if Liftable == false then
		UIS.InputEnded:Connect(function(Input, GPE)
			if GPE then
				return
			end
			
			if Input.KeyCode == Enum.KeyCode.E and Liftable == false then
				return 
			end
		end)
	end
end


Tool.Equipped:Connect(function()
	if Liftable == false then
		Liftable = true
		wait(0.1)
		Check()
		wait()
		print("Liftable set to true!")
	end
end)

Tool.Unequipped:Connect(function()
	if Liftable == true then
		Liftable = false
		wait(0.1)
		Check()
		wait()
		print("Liftable set to false!")
	end
end)
Server Script (In the tool)
-- // Tom_atoes

local Tool = script.Parent

Tool.Fire.OnServerEvent:Connect(function(Player, Check)
	wait(0.1)
	Player.leaderstats.Strength.Value = Player.leaderstats.Strength.Value + 1
	Player.Scales.BWS.Value = Player.Scales.BWS.Value + 0.2
	Player.Scales.BHS.Value = Player.Scales.BHS.Value + 0.1
	Player.Scales.BDS.Value = Player.Scales.BDS.Value + 0.2
	Player.Character:FindFirstChild("Humanoid").BodyWidthScale.Value = Player.Character:FindFirstChild("Humanoid").BodyWidthScale.Value + 0.03
	Player.Character:FindFirstChild("Humanoid").BodyHeightScale.Value = Player.Character:FindFirstChild("Humanoid").BodyHeightScale.Value + 0.02
	Player.Character:FindFirstChild("Humanoid").BodyDepthScale.Value = Player.Character:FindFirstChild("Humanoid").BodyDepthScale.Value + 0.03
end)

I may be wrong but it may have to do with some loop going on thats making the player giant in a short period of time this is just a guess i may be wrong.

1 Like

I also recommend that you check if the player has died in the server sided script

1 Like

Alright, attempting this now

Didn’t do anything, maybe if I take UIS out of the check function it will work.

This seems to have fixed it but I’m still noticing odd stuff in my server logs. I’m not sure if this is just Roblox’s scaling methods trying to override mine, if it’s because of my animation or that I’ve actually done something wrong. But for now this will have to do.

Alright I hope i had some affect in this situation.

1 Like

Thanks for attempting to help, if I have more issues with scaling I’ll repost here