ScaleTo() flings player

Hello! I have made a simple script utilizing ScaleTo, setting it to 5 when a key is pressed. However, at seemingly random intervals, the player gets flung all the way up into the sky, usually being around 32+ million studs. Is there any way to fix this?
I’ve tried anchoring the RootPart then unanchoring, teleporting the player back, but it seems like the player has an absurd amount of velocity when flung, making both of those useless.

Below is my code:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("Shift")

local function changesize(player)
	local char = player.Character
	local scale = char:GetScale()
	if scale >= 5 then
		char:ScaleTo(1)
	else
		char:ScaleTo(5)
	end
end

remote.OnServerEvent:Connect(changesize)
1 Like

Figured it out after some tinkering, AssemblyLinearVelocity and AssemblyAngularVelocity need to be set to 0.

Sample code if anyone else has this issue:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("Shift")

local function changesize(player)
	local char = player.Character
	local root = char.HumanoidRootPart
	local Velocity = root.AssemblyLinearVelocity 
	local RVelocity = root.AssemblyLinearVelocity 
	local scale = char:GetScale()
	if scale >= 5 then
		char:ScaleTo(1)
	else
		char:ScaleTo(5)
		root.AssemblyLinearVelocity = Velocity
		root.AssemblyAngularVelocity = RVelocity -- Prevents fling by setting back player velocity to how it was before ScaleTo was called.
	end
end

remote.OnServerEvent:Connect(changesize)

This is a common problen i had experienced, try saving humanoid root part’s assembly velocity, apply scale and then revert it
smth like

local rootPartVelocity = RootPart.AssemblyLinearVelocity --take the velocity before scaling
char:ScaleTo(newScale) -- method updates velocity of an assembly
RootPart.AssemblyLinearVelocity = rootPartVelocity --revert it

scaling player on the fly is quite janky so be careful when doing it (rubberbands happen and the problem you mentioned)

7 Likes

That’s a better solution, forgot about existing velocity lol

Hi, thanks for this.
It completely fixes the flinging issue when scaling on the client. However it doesn’t seem to completely fix it when scaling on the server.

Do you know if there is a way to scale a moving character, with the new scale replicating to the server?

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