Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help with positions and things?

Asked by 8 years ago
Edited 8 years ago

So I want a crystal to follow above your head, it works, but it is jumpy and stuff. I want it to be really smooth. If you can help me fix this thank you. Btw, this is a local script before you say anything.

function MoveCrystal()
    local character = game.Players.LocalPlayer.Character
    local crystal = workspace.Crystal
    local head = character["Head"]
    local objectSpace = CFrame.new(0, 2, 0)
    local worldSpace = head.CFrame:toWorldSpace(objectSpace)
    crystal.CFrame = worldSpace
end

while wait() do
    MoveCrystal()
end

1 answer

Log in to vote
0
Answered by
sigve10 94
8 years ago
Edited 8 years ago

Right now, you're using a wait(). That wait time can be smooth sometimes, but since you're saying it isn't, you could either use while wait(-1) do, or you could use this script instead of the while:

game:GetService('RunService').RenderStepped:connect(function()
    MoveCrystal()
end)

Stepped is like a while wait() do, but it repeats every 60th of a second!

EDIT: Didn't notice you said it was a localscript. Stepped is for serverscripts, and RenderStepped is for localscripts ;D

0
wait(-1) will wait the same time as wait() or wait(0). The minimum wait time is about a 30th of a second. Perci1 4988 — 8y
0
Well well, anyways, renderstepped is shorter than wait, and I use it myself to make animations go smooth. Recommend you try it ;3 sigve10 94 — 8y
Ad

Answer this question