Hello! So recently, I found a script on the devforum, which makes the player’s character lean right or left, depending on which way the character is moving. I improvised it, and made it lean forwards and backwards too, when the player moves forwards on backwards. But i wanted to make it a server script, so everyone can see the leaning, since instead of using animations, this uses the HumanoidRootPart joint to move the character.
It’s a server script located in game.StarterPlayer.StarterCharacterScripts
and it has a game:GetService("RunService").Stepped
in it, which is just a while true do
but faster, as far as I know.
So this script goes into every player character, and I was wondering, if it would make my game lag if there were too many players.
Edit: Here’s the whole script
HumanoidRootPart = script.Parent.HumanoidRootPart
TweenService = game:GetService("TweenService")
local AngleRight = 0
local AngleForward = 0
local OriginalC0 = HumanoidRootPart.RootJoint.C0
local Direction, Velocity
tweeninfo = TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
game:GetService("RunService").Stepped:Connect(function()
Velocity = HumanoidRootPart.Velocity*Vector3.new(1, 0, 1)
if Velocity.Magnitude > 2 then --Checks if the player is moving
Direction = Velocity.Unit --Makes the velocity a vector3 instead of a CFrame for less complications
AngleRight = HumanoidRootPart.CFrame.RightVector:Dot(Direction)/4.5
AngleForward = HumanoidRootPart.CFrame.LookVector:Dot(Direction)/4.5
else
AngleRight = 0
AngleForward = 0
end
local tween = TweenService:Create(HumanoidRootPart.RootJoint, tweeninfo, {C0 = OriginalC0*CFrame.Angles(AngleForward, -AngleRight, 0)})
tween:Play()
end)