Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to make this more smooth?

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/---

2 comments

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.

0

Thanks!

1 answer

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'

This discussion is preserved as it was. New answers, comments, and votes are closed.