local Player = game.Players.LocalPlayer
script.Parent.Equipped:Connect(function()
if not Player.Character:FindFirstChild("CameraScript") then
local MainScript = script:FindFirstChildWhichIsA("LocalScript"):Clone()
MainScript.Enabled = true
MainScript.Parent = Player.Character
else
Player.Character:FindFirstChild("CameraScript").Enabled = true
end
end)
Camera Script:
--Variables--
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local context = game:GetService("ContextActionService")
--Character/Player--
local plr = game:GetService("Players").LocalPlayer
--Other--
local Camera = game:GetService("Workspace").CurrentCamera
local mouse = plr:GetMouse()
local cameraDB = false
local zoomDB = false
--values--
local xAngle = 0
local yAngle = 0
local cameraPos = Vector3.new(2,0,8.5)
--camera setting--
wait(0.01)
Camera.CameraType = Enum.CameraType.Scriptable
--functions--
context:BindAction("CameraMovement", function(_, _, input)
xAngle = xAngle - input.Delta.x*0.4
yAngle = math.clamp(yAngle - input.Delta.y*0.4,-80,80)
end, false, Enum.UserInputType.MouseMovement)
rs.RenderStepped:Connect(function()
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local c = plr.Character or plr.CharacterAdded:Wait()
local rootPart = c:FindFirstChild("HumanoidRootPart")
--IF STATEMENTS
if c and rootPart then
local startCFrame = CFrame.new((rootPart.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0)
local cameraCFrame = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, cameraPos.Z))
local cameraFocus = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, -50000))
Camera.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p)
end
end)
DeleteScript:
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
rs.RenderStepped:Connect(function()
local Player = game.Players.LocalPlayer.Character
if not Player:FindFirstChild("TestTool") then
local uis = game:GetService("UserInputService")
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
uis.MouseBehavior = Enum.MouseBehavior.Default
script.Parent.Enabled = false
end
end)
The LocalScript is supposed to detect if the player is holding the tool. If he is, then it will duplicate the CameraScript and put it in the player’s Character. The DeleteScript is supposed to stop the CameraScript from running if the player isn’t holding the tool. That’s how the whole model works.