You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Use the ScaleTo function to scale a character’s model by a scale factor determined by the character’s attribute called “Size”
What is the issue? Include screenshots / videos if possible!
When using the ScaleTo function on the character, nothing happens. It doesn’t error nor yield. But at the same time the character model does not grow.
This is the code I have. I placed it within a loop to see if it would repeatedly happen, which it does.
This is ran on the client to scale all player’s characters by their own “Size” attribute divided by a constant.
while task.wait(5) do
for _, otherPlayer in Players:GetPlayers() do
local character = otherPlayer.Character
if character then
local size = character:GetAttribute("Size") or 0
local scale = (1 + (size / sizeConstant))
character:ScaleTo(scale)
print("scaled to",scale,size)
end
end
end
The output of the print is “scaled to 6.812 290500” so the scale factor is not stuck at a value of 1 due to some weird math.
It only seems to not be scaling properly on players who were in the server before the player joined. I’m very confused.
Here is the client who joined after:
It seems like you confused the images in the post.
the client who joined after seems to have inaccurate scaling but the client who joined before seems to be doing fine.
My best guess is that the players are not getting their right ‘scale’ but a mixed one from another player. If you could provide a snapshot of the code that gives them their attributes, it might lead to an answer.
You could also try moving the code to a script with RunContext set to client and leave it somewhere in workspace.
The character on the left is the one that joined after. The POV from the client who has been in the server from the start (right character) has them both scaled correct. The latest client (left character) has their own scale correct but the other client (right character) scale is incorrect.
But I can include a snapshot of where I apply the Size attribute.
This is the codes snipped where the “food” objects are eaten and run the incSize() function.
-- Handle food collisions
charHitbox.HitObject:Connect(function(hitParts)
for _, hitPart in hitParts do
-- Check if hit is a food item
if CollectionService:HasTag(hitPart, "Food") then
munch() -- Munch sfx
-- Add food value to character's size value
incSize(hitPart:GetAttribute("foodValue"))
hitPart.Parent:Destroy()
end
end
end)
This is the incSize() function. It simply increments the attribute value. The
-- Function to increment size
local function incSize(incrementValue)
character:SetAttribute("Size", character:GetAttribute("Size") + incrementValue)
-- Set new leaderboard max size
local currentMaxSize = DataService:GetData(player, "MaxSize")
local currentSize = character:GetAttribute("Size")
-- If current size beats max then make larger
if currentSize > currentMaxSize then
DataService:SetData(player, "MaxSize", currentSize)
end
end
All of this is placed within Players.PlayerAdded and player.CharacterAdded.
I don’t know where the size attribute could get mixed up as the scale works as intended on the older client.
The code is placed within a script that is ran on the client. The print result I gave in my original post is from the client console in game so it runs to completion, just doesn’t scale.
This is more of the client console log. There is current 2 players within the game with 2 different scales but only the local client (which joined after) is properly scaled.
Ahhhh, this really smells like the classic data store problem not being up to date or a value mismatch from GetAsync.
It’s very high likely that the data for one of the players was saved when there was an error in the code and the character was at a small “scale”
if you are able to wipe the data store, it could probably fix the problem. I highly recommend not saving data in studio as it could lead to the same issue very often.
The Size attribute that is stored within the data store has no purpose other than displaying a leaderboard. If you look at that print outputs it shows the calculated scale factor and then right after it shows the Size attribute taking from that character.
Also, this is taken outside of studio. This is within a regular game instance.
In the console I have in this order all following the character name:
Character’s scale found by GetScale() before I scale it using ScaleTo()
The print showing the scale I was to set it to following by their Size attribute
Finally the character’s scale afterwords found by GetScale()
This shows that Roblox is in fact updating the scale and it showing it at the proper value in the code but it displays wrong.
Is it possible there is some weird StreamingEnabled behaviour happening where the client is able to set the scale for a model that shouldn’t even exist and now it thinks that the, in this case 3x scale, is the default size?
I’m going to try and disable StreamingEnabled to see if it fixes it.
Seems disabling StreamingEnabled fixed the issue?
I was under the assumption that if it was outside of the render distance, trying to access the model within a script would result in nil?
Like if I did :FindFirstChild(model) on a model outside the map, it would return nil?
Is player.Character different>?
Changing the starter character’s model to atomic or persistent just creates a whole other error. I don’t think the resources will be a problem so I will leave it with StreamEnabled inactive.