generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Field of View Help!

Previous Thread :: Next Thread 
Stephanie_Angela is not online. Stephanie_Angela
Joined: 28 Oct 2016
Total Posts: 55
06 Jan 2017 09:26 AM
Hello Everyone. I need some help as I have a problem with my script. The purpose is that it zooms in when right click is pressed on a tool. It won't work however, as it effects the player even if the tool isn't equipped. Much help is appreciated!


Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
local tool = script.parent

local function onEquip
mouse.Button2Down:connect(function()
game.Workspace.Camera.FieldOfView = 50
end)

mouse.Button2Up:connect(function()
game.Workspace.Camera.FieldOfView = 80
end)
Report Abuse
Stephanie_Angela is not online. Stephanie_Angela
Joined: 28 Oct 2016
Total Posts: 55
06 Jan 2017 09:28 AM
Oops, I meant it wont work when I use onequip function :p Sorry
Report Abuse
Stephanie_Angela is not online. Stephanie_Angela
Joined: 28 Oct 2016
Total Posts: 55
06 Jan 2017 09:31 AM
Let me rephrase that again. When I put the script into the tool, it doesn't work. Can someone help me fix it?
Report Abuse
jordan0810 is not online. jordan0810
Joined: 03 Jun 2012
Total Posts: 846
06 Jan 2017 09:39 AM
Try the code below, i have not tested it however.

script.Parent.Equipped:connect(function(mouse)
mouse.Button2Down:connect(function()
game.Workspace.Camera.FieldOfView = 50
end)

mouse.Button2Up:connect(function()
game.Workspace.Camera.FieldOfView = 80
end)
end)

Report Abuse
Stephanie_Angela is not online. Stephanie_Angela
Joined: 28 Oct 2016
Total Posts: 55
06 Jan 2017 09:48 AM
Yes, it works perfectly! Just one more question. If you are up to the challenge, is it possible to play an animation while having Button2Down?

If you don't want to, you don't have to. Only if your up to the challenge!

Thanks.
Report Abuse
jordan0810 is not online. jordan0810
Joined: 03 Jun 2012
Total Posts: 846
06 Jan 2017 09:53 AM
Again not tested but should work, just insert your animation id.

local char = game:GetService("Players").LocalPlayer.Character
local animation = Instance.new("Animation")
animation.AnimationId = "animationIdHere"

mouse.Button2Down:connect(function()
local animationTrack = char:WaitForChild("Humanoid"):LoadAnimation(animation)
animationTrack:Play()
end)
Report Abuse
Stephanie_Angela is not online. Stephanie_Angela
Joined: 28 Oct 2016
Total Posts: 55
06 Jan 2017 10:13 AM
It works, but there is a problem. One animation overlaps the other, so I tried to fix that, but there is something wrong. Please see what you can do. I praise you with lots of gratitude.

script.Parent.Equipped:connect(function(mouse)
mouse.Button2Down:connect(function()
game.Workspace.Camera.FieldOfView = 50
end)

mouse.Button2Up:connect(function()
game.Workspace.Camera.FieldOfView = 80
end)
end)

Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local char = game:GetService("Players").LocalPlayer.Character
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset?id=602571245"
if Button2Up = then animation.AnimationId = "http://www.roblox.com/asset?id=601545837"
end


mouse.Button2Down:connect(function()
local animationTrack = char:WaitForChild("Humanoid"):LoadAnimation(animation)
animationTrack:Play()
end)
Report Abuse
Stephanie_Angela is not online. Stephanie_Angela
Joined: 28 Oct 2016
Total Posts: 55
06 Jan 2017 10:14 AM
*if Button2Up = true then
Report Abuse
OAuth2 is not online. OAuth2
Joined: 27 Nov 2016
Total Posts: 751
06 Jan 2017 10:17 AM
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local tool = script.Parent
local camera = game.Workspace.CurrentCamera -- Use CurrentCamera. This is the player's local camera
local anim1 = Instance.new("Animation")
anim1.AnimationId = "" -- Input
local anim2 = Instance.new("Animation")
anim2.AnimationId = "" -- Input

tool.Equipped:connect(function()
mouse.Button2Down:connect(function()
camera.FieldOfView = 50
local anim = Player.Character.Humanoid:LoadAnimation(anim1)
anim:Play()
end)
mouse.Button1Up:connect(function()
camera.FieldOfView = 80
local anim = Player.Character.Humanoid:LoadAnimation(anim2)
anim:Play()
end)
end)


Report Abuse
jordan0810 is not online. jordan0810
Joined: 03 Jun 2012
Total Posts: 846
06 Jan 2017 10:22 AM
Not tested as usual but this should work ;) Just change animLenth to how long the animation is.


local char = game:GetService("Players").LocalPlayer.Character
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset?id=602571245"
local animTrack = nil
local animLength = 2 --How long the animation lasts (seconds)
local debounce = false

script.Parent.Equipped:connect(function(mouse)
mouse.Button2Down:connect(function()
if not debounce then
debounce = true
game.Workspace.Camera.FieldOfView = 50
animation.AnimationId = "http://www.roblox.com/asset?id=602571245"
animationTrack = char:WaitForChild("Humanoid"):LoadAnimation(animation)
animationTrack:Play()
wait(animLength)
debounce = false
end
end)

mouse.Button2Up:connect(function()
if not debounce then
debounce = true
game.Workspace.Camera.FieldOfView = 80
animation.AnimationId = "http://www.roblox.com/asset?id=601545837"
animationTrack = char:WaitForChild("Humanoid"):LoadAnimation(animation)
animationTrack:Play()
wait(animLength)
debounce = false
end
end)
end)

Report Abuse
jordan0810 is not online. jordan0810
Joined: 03 Jun 2012
Total Posts: 846
06 Jan 2017 10:23 AM
The third line can be removed, as it is no longer needed.
Line 3: animation.AnimationId = "http://www.roblox.com/asset?id=602571245"
Report Abuse
Stephanie_Angela is not online. Stephanie_Angela
Joined: 28 Oct 2016
Total Posts: 55
06 Jan 2017 10:30 AM
Thank you all for your help. I will take it from there. This thread is officially closed.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image