I made a simple zoom script, that when you hold right click it tweens your fov (creating a zoom effect) I have the basic code down, and it works, but the tween animation keeps resetting and playing again, creating this pumping camera effect when its held down. Is there a way I can make it play once or something?
Here is the code:
--// Services
local UserInputService = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local camera = game.Workspace.Camera
--// Objects
local fovIn = ts:Create(
camera,
TweenInfo.new(.5),
{FieldOfView = 50}
)
local fovOut = ts:Create(
camera,
TweenInfo.new(.5),
{FieldOfView = 70}
)
local Held = false
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton2 then
Held = true
end
end)
UserInputService.InputEnded:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton2 then
Held = false
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if Held == true then
fovIn:Play()
elseif Held == false then
fovOut:Play()
end
end)
Yep, I am an idiot, I left in a audio visualizer script that was constantly resetting the fov to 70. Wow. Its completely fixed now, thanks for the help.
local tweenInfo = TweenInfo.new(
2, -- Time it takes for Tween to carry out.
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely) -- This may be the one your looking for. Make it 0 to stop repeating.
false, -- Reverses (tween will reverse once reaching it's goal) -- this may also be a factor. If this is true you might want to make it false,
0 -- Time before Tween starts.
)
I put some comments for you to understand the basic functions of TweenInfo
local uis = game:GetService("UserInputService") --gets user input service
local ts = game:GetService("TweenService") --gets tween service
local player = game.Players.LocalPlayer --finds the player
local cam = workspace.CurrentCamera --finds the player's cam
local mouse = player:GetMouse() --gets the player's mouse
local ti = TweenInfo.new(0.5) --defines a new tween info with a 0.5 second interval
local fovIn = { --fovIn properties
FieldOfView = 50
}
local fovOut = { --fovOut properties
FieldOfView = 70
}
mouse.Button2Down:Connect(function() --right click function
local tween = ts:Create(cam, ti, fovIn) --creates a tween
tween:Play() --plays that tween
end
mouse.Button2Up:Connect(function() --right click ended function
local tween = ts:Create(cam, ti, fovOut) --creates a tween
tween:Play() --plays that tween
end