Whenever I scale my character at runtime, sometimes the scaling doesnt not replicate to client thus my character looks small on client and large on server
this has about a 15-20% chance of happening at runtime
this happens both in game and in studio and only happens at runtime
Players.PlayerAdded:Connect(function(Player)
local data = DataModule:ReturnData(Player)
local character = Player.Character or Player.CharacterAdded:Wait()
data[2].LoadedStage = StageModule:GetStage(Player)
local function characterAdded(char)
character = char
StageModule:LoadStage(Player, char)
GrowModule:UpdateTempScales(data, character) -- I update a table with scales
GrowModule:ApplySize(data, character) -- I update the characters humanoid scales based on the table of scales
end
characterAdded(character)
Player.CharacterAdded:Connect(characterAdded)
end)
function GrowModule:UpdateTempScales(Data, Character)
if Data and Character then
local loadedStage = Data[2].LoadedStage
local humDesc = loadedStage.HumDesc
local humanoid = Character.Humanoid
Data[2].ScaleObjects = {humanoid.BodyDepthScale, humanoid.HeadScale, humanoid.BodyHeightScale, humanoid.BodyWidthScale}
Data[2].DefaultScales = {humDesc.DepthScale, humDesc.HeadScale, humDesc.HeightScale, humDesc.WidthScale}
end
end
function GrowModule:ApplySize(Data, Character)
if Data and Character then
local scaleObjects = Data[2].ScaleObjects
local defaultScales = Data[2].DefaultScales
local loadedStage = Data[2].LoadedStage
local size = (Data[1].Size * loadedStage.ScalePerSize)
for i = 1, #scaleObjects do
print("Scaled")
scaleObjects[i].Value = defaultScales[i] + (defaultScales[i] * size)
end
end
end
is this a bug, or is this an issue on my part?
I looked around online but the only results are related to animations
Edit:
there are no errors and if I reset (which scales when I spawn) it works normally
Edit2:
after testing a lot it’s not strictly limited to runtime and happens when character loads, I’m guessing it’s because I’m adding the character and then scaling instantly going to investigate some more
You should just check if the size values exist and if not then WaitForChild for them, just to be safe.
wait() is bad practice for loading since the time to load could vary, and using wait() can either fail if the values haven’t loaded yet, or add unnecessary time to the execution otherwise.
wouldn’t adding that be redundant as that event was already fired?
Players.PlayerAdded:Connect(function(Player)
local data = DataModule:ReturnData(Player)
local character
data[2].LoadedStage = StageModule:GetStage(Player)
local function characterAdded(char)
character = char
StageModule:LoadStage(Player, char)
GrowModule:UpdateTempScales(data, character) -- I update a table with scales
wait(1)
GrowModule:ApplySize(data, character) -- I update the characters humanoid scales based on the table of scales
char.Humanoid.Died:Connect(function()
char:Destroy()
Player:LoadCharacter()
end)
end
Player.CharacterAdded:Connect(characterAdded)
Player:LoadCharacter()
end)
It could just be the way the roblox engine works then, where things won’t replicate unless they are actually moving I’m guessing. For example, roblox doesn’t replicate anchored parts. I’m sure there’s some condition that is caused roblox to decide that the scale doesn’t need to be replicated.
In that case then waiting might be the best option
That’s what I was thinking but he said the values are being updated. If they didn’t exist yet then attempting to change them would give an attempt to index a nil value error
Yeah I think waiting will be fine in this case if there are no other solutions because I don’t believe the issue is with loading because it also happens sometimes when I respawn
@PirateOnThePlank the values are loaded because I change the value of them, when the issue is happening if I go to the body scale values on client or server they are set to the correct numbers but rather the size itself is not replicating but the values are
function GrowModule:GetScaledDescription(Data)
local scaleNames = {"DepthScale", "HeadScale", "HeightScale", "WidthScale"}
local defaultScales = Data[2].DefaultScales
local loadedStage = Data[2].LoadedStage
local size = (Data[1].Size * loadedStage.ScalePerSize)
local scaledStage = loadedStage.HumDesc:Clone()
for i = 1, #scaleNames do
scaledStage[scaleNames[i]] = defaultScales[i] + (defaultScales[i] * size)
end
return scaledStage
end