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

Shift to run camera move back? FieldOfView help...

I want my fov to move back when tapping shift and i alredy got a shift to sprint script. can I mabye get some little help with the last part - where the camera zooms out. right now it just "teleports" back when you hit shift and i want a smoot animation. Can somebody help me tnx!

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
	local CurrentTime = tick()
	if input.KeyCode == Enum.KeyCode.LeftShift then
		if humanoid.MoveDirection.Magnitude > 0 then
			game.Workspace.Camera.FieldOfView = 90

			Character.Humanoid.WalkSpeed = 25
			local Anim = Instance.new('Animation')
			Anim.AnimationId = 'rbxassetid://5984168294'
			PlayAnim = Character.Humanoid:LoadAnimation(Anim)
			PlayAnim:Play()
		else
		
			if humanoid.MoveDirection.Magnitude < 0 then
				PlayAnim:Stop()
			end
			
		end
		
	end
	
end)
UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		game.Workspace.Camera.FieldOfView = 70
		Character.Humanoid.WalkSpeed = 9
		PlayAnim:Stop()
	end
end)

1 comment

0

Updated my answer for your comment. Hope that helps a little bit more.

1 answer

I highly recommend looking into using tween service for this task.

Essentially you'll want to set up the tween to change the field of view from 70 to 90 in the InputBegan. And 90 to 70 in the input ended.

Try it out after looking into Tween Service and if you still can't get it afterwards let me know and I'll help you work through a solution.

EDIT:

Since you said you had difficulty with tween service I'll go over the basics really quickly.

local ts = game:GetService("TweenService")


local info = TweenInfo.new(
	0.2, -- Time
	Enum.EasingStyle.Back, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
local tweenObject = ts:Create(game.Workspace.CurrentCamera,info,{FieldOfView = 90})
local normal = ts:Create(game.Workspace.CurrentCamera,info,{FieldOfView = 70})

tweenObject:Play()
wait(0.5)
normal:Play()

Line 1: Get the tween service

Line 4: We start setting up the tween info, so that we can make the animation smooth (this is all about style)

Line 12: We make our first tween object that we can play when we want to go to FOV 90. Line 13: We make our second tween for resetting to normal.

After that we can use our tween objects to play these animations using their "Play" method.

3 comments

0

The only thing is that I am not familiar with tween service and I tried it out but i can't get a hold of it..

0

Ok now I get it a little more but where do I put it in my script? tnx for all the help!

0

You could for instance set up the tweens at the start of the script, and then just play the tweens inside the events.

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