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

What does "tick()" do exactly and how does it work? [closed]

Asked by
clrik 8
6 years ago

This question already has an answer here:

What does the tick function in ROBLOX do?

I am using a script for a game that I am making. I am confused on one of the scripts that I am using has "tick" in it.

repeat wait() until game.Players.LocalPlayer.Character

camera = game.Workspace.CurrentCamera
character = game.Players.LocalPlayer.Character

Z = 0

damping = character.Humanoid.WalkSpeed / 2

PI = 3.1415926

tick = PI / 2

running = false
strafing = false

character.Humanoid.Strafing:connect(function(bool)
    strafing = bool
end)

character.Humanoid.Jumping:connect(function()
    running = false
end)

character.Humanoid.Swimming:connect(function()
    running = false
end)

character.Humanoid.Running:connect(function(speed)
    if speed > 0.1 then
        running = true
    else
        running = false
    end
end)

function mix(par1, par2, factor)
    return par2 + (par1 - par2) * factor
end

while true do
    game:GetService("RunService").RenderStepped:wait()

    fps = (camera.CoordinateFrame.p - character.Head.Position).Magnitude

    if fps < 0.52 then
        Z = 1
    else
        Z = 0
    end

    if running == true and strafing == false then
        tick = tick + character.Humanoid.WalkSpeed / 92 --Calculate Bobbing speed.
    else
        if tick > 0 and tick < PI / 2 then
            tick = mix(tick, PI / 2, 0.9)
        end
        if tick > PI / 2 and tick < PI then
            tick = mix(tick, PI / 2, 0.9)
        end
        if tick > PI and tick < PI * 1.5 then
            tick = mix(tick, PI * 1.5, 0.9)
        end
        if tick > PI * 1.5 and tick < PI * 2 then
            tick = mix(tick, PI * 1.5, 0.9)
        end
    end

    if tick >= PI * 2 then
        tick = 0
    end 

    camera.CoordinateFrame = camera.CoordinateFrame * 
        CFrame.new(math.cos(tick) / damping, math.sin(tick * 2) / (damping * 2), Z) * 
        CFrame.Angles(0, 0, math.sin(tick - PI * 1.5) / (damping * 20)) --Set camera CFrame
end

If I know what tick does, I can learn how to use it in different scripts; if it does have some sort of other use. . .

0
tick() is a global function. It's the number of seconds since January 1, 1970 at 0:00 UTC, but with this script, tick is just a variable, and has nothing to do with the function. UgOsMiLy 1074 — 6y
0
Thanks but, post it as an answer next time ;( clrik 8 — 6y
0
^ A bit of research's all that's necessary. >-> TheeDeathCaster 2368 — 6y

Marked as Duplicate by cabbler, User#20388, and TheeDeathCaster

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago

In this case there using tick as a variable to represent half of pi radians which is 90 degrees, but in lua tick() is the time in seconds from the unix epoch ,January 1st, 1970.

Ad