Hey everyone,
I made a script to rotate the player in the \ | / directions. After a lot of struggling, I finally got it to work. But when I run the game, it looks really smooth on the server, but on the client, it looks bad and laggy.
Does anyone know why this happens?
Thanks!
Heres Script
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.PrimaryPart = character:FindFirstChild("Right Leg")
if character:FindFirstChild("Animate") then
character.Animate:Destroy()
end
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.JumpHeight = 0
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
task.wait(0.1)
local base = character:GetPivot()
local t = 0
local speed = 3.7
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
t = t + deltaTime * speed
local angle = 45 * math.cos(t)
local newCFrame = base * CFrame.Angles(math.rad(angle), 0, 0)
if character.PrimaryPart.CFrame ~= newCFrame then
character:PivotTo(newCFrame)
end
end)
end)
end)
Heres Client Video
And Heres Server Video