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

Is there a way to make this more smooth?

Asked by 9 years ago

I've made a sprinting script when you press 'q', you sprint. Your camera also zooms out a little. But when you rapidly press 'q' the camera looks bad. How would i go about making it look smother?

here is the script:

mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:connect(function(key)
    if key == "q" then
        script.Parent:TweenSize(UDim2.new(0,100,0,50),"InOut","Quad",2,true)
        script.Parent:TweenSize(UDim2.new(1,100,0,50),"InOut","Quad",6,false)
        wait()
        script.Parent.BackgroundColor3 = Color3.new(0,0,1)
        if game.Workspace.CurrentCamera.FieldOfView ~= 80 then
        for i = 70,80,1 do
                game:GetService("RunService").RenderStepped:wait()
                game.Workspace.CurrentCamera.FieldOfView = i
            end
        end
    end
end)

mouse.KeyUp:connect(function(key)
    if key == "q" then
        script.Parent.BackgroundColor3 = Color3.new(0,1,0)
        script.Parent:TweenSize(UDim2.new(1,100,0,50),"InOut","Quad",6,true)
        script.Parent:TweenSize(UDim2.new(0,100,0,50),"InOut","Quad",2,false)
        if game.Workspace.CurrentCamera.FieldOfView ~= 70 then
            for i = 80,70,-1 do
                game:GetService("RunService").RenderStepped:wait()
                game.Workspace.CurrentCamera.FieldOfView = i
            end
        end
    end
end)

here is the game so you see what it looks like:

http://www.roblox.com/games/197480972/---

0
The Sprint is amazing. The people who keep pressing Q are just noobs who want unlimited sprint. It's good as is. Keep it up, and oh, I like that counter that keeps going up the higher you get. GreekGodOfMLG 244 — 9y
0
Thanks! Senor_Chung 210 — 9y

1 answer

Log in to vote
0
Answered by
Muoshuu 580 Moderation Voter
9 years ago

You could set a debounce that does not allow the function to fire if in the middle of firing.

Example:

mouse = game.Players.LocalPlayer:GetMouse()
local firing=false

mouse.KeyDown:connect(function(key)
    if key == "q" then
        if not firing then
            firing=true
            script.Parent:TweenSize(UDim2.new(0,100,0,50),"InOut","Quad",2,true)
            script.Parent:TweenSize(UDim2.new(1,100,0,50),"InOut","Quad",6,false)
            wait()
            script.Parent.BackgroundColor3 = Color3.new(0,0,1)
            if game.Workspace.CurrentCamera.FieldOfView ~= 80 then
                for i = 70,80,1 do
                    game:GetService("RunService").RenderStepped:wait()
                    game.Workspace.CurrentCamera.FieldOfView = i
                end
            end
            firing=false
        end
    end
end)

mouse.KeyUp:connect(function(key)
    if key == "q" then
        if not firing then
            firing=true
            script.Parent.BackgroundColor3 = Color3.new(0,1,0)
            script.Parent:TweenSize(UDim2.new(1,100,0,50),"InOut","Quad",6,true)
            script.Parent:TweenSize(UDim2.new(0,100,0,50),"InOut","Quad",2,false)
            if game.Workspace.CurrentCamera.FieldOfView ~= 70 then
                for i = 80,70,-1 do
                    game:GetService("RunService").RenderStepped:wait()
                    game.Workspace.CurrentCamera.FieldOfView = i
                end
            end
            firing=false
        end
    end
end)

Click here for more information on 'debounce'

Ad

Answer this question