Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

camera doesn't work normally, what should I do?

Asked by 4 years ago

I have a gun, inside the gun I made a script to change normal mode into aiming mode:

local Camera = workspace.CurrentCamera

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local mouse = Player:GetMouse()
local camera = workspace.CurrentCamera
local Tool = script.Parent

local aiming = Tool.Aiming
local Animation = Instance.new('Animation',script.Parent)
Animation.AnimationId = 'rbxassetid://4423111511'
local AnimationTrack = Humanoid:LoadAnimation(Animation)
local runservice = game:GetService("RunService");

local Animation2 = Instance.new('Animation',script.Parent)
Animation2.AnimationId = 'rbxassetid://4423251185'
local AnimationTrack2 = Humanoid:LoadAnimation(Animation2)


Tool.Activated:Connect(function()
    AnimationTrack:Play()
end)

Tool.Equipped:Connect(function()
    AnimationTrack2:Play()
end)

Tool.Unequipped:Connect(function()
    AnimationTrack2:Stop()
end)

Tool.Equipped:Connect(function()
mouse.KeyDown:Connect(function(k)
--Player.CameraMode = Enum.CameraMode.LockFirstPerson
--Camera.CameraSubject = aiming
--Camera.CameraType = 7
--Camera.Focus = aiming.CFrame
if k == "e" then
function CameraUpdate()
local target = Tool.Aiming --Useful variable for defining a target
local camera = workspace.CurrentCamera --Gets the current camera from the workspace
camera.CameraType = Enum.CameraType.Scriptable --Sets the camera type. Scriptable makes it so the camera doesn't move at all when the position is set
camera.CameraSubject = target -- Sets the target for the camera 
    camera.CoordinateFrame = CFrame.new(target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, 0, 0) --Rotation
                           * CFrame.new(0, 0,.2)       --Move the camera backwards 5 units
Tool.Mode.Value = 1
Camera.CFrame = target.CFrame - target.CFrame.lookVector
end

runservice:BindToRenderStep("VertCamera", Enum.RenderPriority.Camera.Value, CameraUpdate);
end
mouse.KeyUp:Connect(function(key)
    if k == "e" then
function CameraUpdate2()
local target = Humanoid
local camera = workspace.CurrentCamera 
camera.CameraType = Enum.CameraType.Custom 
camera.CameraSubject = target 

Tool.Mode.Value = 0
end
CameraUpdate2()
runservice:BindToRenderStep("VertCamera", Enum.RenderPriority.Camera.Value, CameraUpdate2);
end
end)
end)


end)

*Note: When aiming the aiming part is invisible and in a line with the crosshair, so that you can aim without creating the fake arm. There are two problem: 1) When pressing E and pressing W to go straight, the character moves a little bit left and when pressing S to go backwards the camera keep spinning 2) when I don't press E anymore, the camera is abnormal, like it is scriptable, instead of fixed.

Please, let me know the problem. Thanks a lot.

Answer this question