|
| 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 |
|
|
|
| 06 Jan 2017 09:28 AM |
| Oops, I meant it wont work when I use onequip function :p Sorry |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|