Can Someone help me to where when i stop aiming in it will put my camera back to the normal roblox 3ed person view and follow my player like regular i try to put it to custom and this happens
local UIS = game:GetService("UserInputService")
local players = game:GetService("Players")
local plr = players.LocalPlayer
local tool = script.Parent
local deb = false -- Moved debounce variable here so it's shared across events
local Animations = script.Parent:FindFirstChild("Animations")
-- Reloading logic with debounce
UIS.InputBegan:Connect(function(input, gameprocessed)
if gameprocessed then return end
if input.KeyCode == Enum.KeyCode.R then
if not deb then -- Check if debounce is false
if plr.Character:FindFirstChild(tool.Name) then
deb = true
local AnimTrack = plr.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(Animations.Reload)
AnimTrack:Play()
wait(5) -- Wait for 5 seconds (reload time)
deb = false -- Reset debounce after the wait
end
end
end
end)
-- Right-click logic with debounce for aiming
UIS.InputBegan:Connect(function(input, gameprocessed)
if gameprocessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Right Clicked")
if not deb then -- Check if debounce is false
if plr.Character:FindFirstChild(tool.Name) then
local AnimTrack = plr.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(Animations.Aim)
AnimTrack:Play()
local Camera = game.Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local cameraPart = script.Parent.CameraPart -- The part that the camera will follow
-- Set the camera to scriptable mode
Camera.CameraType = Enum.CameraType.Scriptable
-- Update the camera's CFrame to match the camera part's CFrame every frame
RunService.RenderStepped:Connect(function()
Camera.CFrame = cameraPart.CFrame
end)
end
end
end
end)
-- Right-click release logic for stopping aim
UIS.InputEnded:Connect(function(input, gameprocessed)
if gameprocessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Right Click Ended")
if not deb then -- Check if debounce is false
if plr.Character:FindFirstChild(tool.Name) then
local AnimTrack = plr.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(Animations.Aim)
AnimTrack:Stop() -- Stop aiming animation when right-click is released
for i,v in pairs(plr.Character.Humanoid:GetPlayingAnimationTracks()) do
if v.Name== "Aim" then
v:Stop()
v:Destroy()
end
end
local idleanimtrack = plr.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(Animations.Idle)
local Camera = game.Workspace.CurrentCamera
local cameraPart = script.Parent.CameraPart -- The part that the camera will follow
Camera.CameraType = Enum.CameraType.Custom
idleanimtrack:Play()
Camera = Enum.CameraType.Custom
end
end
end
end)
-- Idle animation handling when tool is equipped
local idleanimtrack = plr.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator"):LoadAnimation(Animations.Idle)
tool.Equipped:Connect(function()
idleanimtrack:Play()
end)
tool.Unequipped:Connect(function()
idleanimtrack:Stop()
end)
i cant figure out how to do it i had it at one point to where it did stop when i stoped holding the aim but the camera was just frozen in the air and not back to normal.