Avatar Scaling / data store not working?
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! Also include what I'm doing wrong.
DataStore script:
001 | local Data = game:GetService( "DataStoreService" ):GetDataStore( "I" ) |
003 | game:GetService( "Players" ).PlayerAdded:Connect( function (Plr) |
007 | local Stats = Instance.new( "Folder" , Plr) |
008 | Stats.Name = "leaderstats" |
010 | local Strength = Instance.new( "IntValue" , Stats) |
011 | Strength.Name = "Strength" |
013 | local Rebirths = Instance.new( "IntValue" , Stats) |
014 | Rebirths.Name = "Rebirths" |
018 | local Scales = Instance.new( "Folder" , Plr) |
019 | Scales.Name = "Scales" |
021 | local BWS = Instance.new( "NumberValue" , Scales) |
024 | local BHS = Instance.new( "NumberValue" , Scales) |
027 | local BDS = Instance.new( "NumberValue" , Scales) |
032 | local Data 1 = Data:GetAsync(Plr.UserId) |
035 | for i, v in pairs (Stats:GetChildren()) do |
036 | v.Value = Data 1 [ v.Name ] |
038 | for i, v in pairs (Scales:GetChildren()) do |
039 | v.Value = Data 1 [ v.Name ] |
041 | print (Plr.Name .. "'s data loaded successfully!" ) |
050 | for i, v in pairs (Stats:GetChildren()) do |
051 | SaveData [ v.Name ] = v.Value |
054 | for i, v in pairs (Scales:GetChildren()) do |
055 | SaveData [ v.Name ] = v.Value |
058 | Data:SetAsync(Plr.UserId, SaveData) |
059 | print (Plr.Name .. "'s data autosaved successfully!" ) |
064 | Plr.CharacterAdded:Connect( function (Char) |
066 | repeat wait() until Char:FindFirstChild( "Humanoid" ) |
067 | local Humanoid = Char:WaitForChild( "Humanoid" ) |
068 | local BDS = Humanoid:WaitForChild( "BodyDepthScale" ) |
069 | local BHS = Humanoid:WaitForChild( "BodyHeightScale" ) |
070 | local BWS = Humanoid:WaitForChild( "BodyWidthScale" ) |
071 | if Plr.leaderstats.Strength.Value = = 0 then |
075 | Plr:FindFirstChild( "Scales" ).BDS.Value = 0.2 |
076 | Plr:FindFirstChild( "Scales" ).BHS.Value = 1 |
077 | Plr:FindFirstChild( "Scales" ).BWS.Value = 0.2 |
079 | BWS.Value = Plr:FindFirstChild( "Scales" ).BWS.Value |
080 | BHS.Value = Plr:FindFirstChild( "Scales" ).BHS.Value |
081 | BDS.Value = Plr:FindFirstChild( "Scales" ).BDS.Value |
086 | game:GetService( "Players" ).PlayerRemoving:Connect( function (Plr) |
087 | local Stats = Plr:FindFirstChild( "leaderstats" ) |
088 | local WeightStats = Plr:FindFirstChild( "Scales" ) |
091 | for i, v in pairs (Stats:GetChildren()) do |
092 | SaveData [ v.Name ] = v.Value |
094 | for i, v in pairs (WeightStats:GetChildren()) do |
095 | if v.ClassName = = "NumberValue" then |
096 | SaveData [ v.Name ] = v.Value |
099 | Data:SetAsync(Plr.UserId, SaveData) |
100 | print (Plr.Name .. "'s data autosaved successfully!" ) |
Tool local script:
01 | local Tool = script.Parent |
02 | local Player = game:GetService( "Players" ).LocalPlayer |
03 | local Animation = Tool:WaitForChild( "Handle" ).Animation |
05 | local UIS = game:GetService( "UserInputService" ) |
06 | local LastActivated = tick() |
09 | if Liftable = = true then |
10 | UIS.InputBegan:Connect( function (Input, GPE) |
15 | if Input.KeyCode = = Enum.KeyCode.E and Liftable = = true then |
16 | if tick() - LastActivated > = 2.5 then |
17 | print ( "Input Success" ) |
18 | local AnimPlay = Player.Character:FindFirstChild( "Humanoid" ):LoadAnimation(Animation) |
20 | Tool.Fire:FireServer(Player, "IsUpdatedByGame" ) |
21 | LastActivated = tick() |
27 | if Liftable = = false then |
28 | UIS.InputEnded:Connect( function (Input, GPE) |
33 | if Input.KeyCode = = Enum.KeyCode.E and Liftable = = false then |
41 | Tool.Equipped:Connect( function () |
42 | if Liftable = = false then |
47 | print ( "Liftable set to true!" ) |
51 | Tool.Unequipped:Connect( function () |
52 | if Liftable = = true then |
57 | print ( "Liftable set to false!" ) |
Tool Server script:
01 | local Tool = script.Parent |
03 | Tool.Fire.OnServerEvent:Connect( function (Player, Check) |
05 | Player.leaderstats.Strength.Value = Player.leaderstats.Strength.Value + 1 |
06 | Player.Scales.BWS.Value = Player.Scales.BWS.Value + 0.2 |
07 | Player.Scales.BHS.Value = Player.Scales.BHS.Value + 0.1 |
08 | Player.Scales.BDS.Value = Player.Scales.BDS.Value + 0.2 |
09 | Player.Character:FindFirstChild( "Humanoid" ).BodyWidthScale.Value = Player.Character:FindFirstChild( "Humanoid" ).BodyWidthScale.Value + 0.03 |
10 | Player.Character:FindFirstChild( "Humanoid" ).BodyHeightScale.Value = Player.Character:FindFirstChild( "Humanoid" ).BodyHeightScale.Value + 0.02 |
11 | Player.Character:FindFirstChild( "Humanoid" ).BodyDepthScale.Value = Player.Character:FindFirstChild( "Humanoid" ).BodyDepthScale.Value + 0.03 |