So whenever the gun is in my backpack, equipped or not. The click detector doesnt work. I think its because of the camera script in the gun (it makes it third person) but idk. Ill send a code and a script.
Camera Script V
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Character = Player.Character
if Character == nil then
Player.CharacterAdded:wait()
end
local cameraOffset = Vector3.new(2,2,8)
local glock = script.Parent
local mouse = Player:GetMouse()
local cooldown = false
UserInputService.InputBegan:connect(function(input,processed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and script.Parent.Parent:FindFirstChild("Humanoid") then
script.Parent.RemoteEvent:FireServer(mouse.Hit.p)
end
end)
local humanoid = Character:WaitForChild("Humanoid")
local rootPart = Character:WaitForChild("HumanoidRootPart")
local cameraAngleX = 0
local cameraAngleY = 0
humanoid.AutoRotate = false
local function playerInput(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Change then
cameraAngleX -= inputObject.Delta.X
cameraAngleY = math.clamp(cameraAngleY - inputObject.Delta.Y * 0.4, -75, 75)
end
end
ContextActionService:BindAction("PlayerInput",playerInput,false,Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
if script.Parent.Parent == Character then
local startCFrame = CFrame.new(rootPart.CFrame.Position)*CFrame.Angles(0,math.rad(cameraAngleX),0) * CFrame.Angles(math.rad(cameraAngleY),0,0)
local cameraCFrame = startCFrame:PointToWorldSpace(cameraOffset)
local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(cameraAngleX,cameraOffset.Y, -100000))
camera.CFrame = CFrame.lookAt(cameraCFrame,cameraFocus)
local lookingCFrame = CFrame.lookAt(rootPart.Position, camera.CFrame:PointToWorldSpace(Vector3.new(0,0,-100000)))
rootPart.CFrame = CFrame.fromMatrix(rootPart.Position,lookingCFrame.XVector,rootPart.CFrame.YVector)
end
end)
--[[Player.CharacterAdded:connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local rootPart = char:WaitForChild("HumanoidRootPart")
local cameraAngleX = 0
local cameraAngleY = 0
humanoid.AutoRotate = false
local function playerInput(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Change then
cameraAngleX -= inputObject.Delta.X
cameraAngleY = math.clamp(cameraAngleY - inputObject.Delta.Y * 0.4, -75, 75)
end
end
ContextActionService:BindAction("PlayerInput",playerInput,false,Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
if script.Parent.Parent == char then
local startCFrame = CFrame.new(rootPart.CFrame.Position)*CFrame.Angles(0,math.rad(cameraAngleX),0) * CFrame.Angles(math.rad(cameraAngleY),0,0)
local cameraCFrame = startCFrame:PointToWorldSpace(cameraOffset)
local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(cameraAngleX,cameraOffset.Y, -100000))
camera.CFrame = CFrame.lookAt(cameraCFrame,cameraFocus)
local lookingCFrame = CFrame.lookAt(rootPart.Position, camera.CFrame:PointToWorldSpace(Vector3.new(0,0,-100000)))
rootPart.CFrame = CFrame.fromMatrix(rootPart.Position,lookingCFrame.XVector,rootPart.CFrame.YVector)
end
end)
end)]]
local function focusControl(actionName, inputState, inputObject)
if script.Parent.Parent:FindFirstChild("Humanoid") then
if inputState == Enum.UserInputState.Begin then
camera.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
--UserInputService.MouseIconEnabled = false
mouse.Icon = "rbxassetid://8230755404"
end
else
camera.CameraType = Enum.CameraType.Custom
mouse.Icon = [[]]
Player.Character.Humanoid.AutoRotate = true
end
end-- string name function add touch button inputTypes
ContextActionService:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
local h = Character.Humanoid:WaitForChild("Animator"):LoadAnimation(script.Parent.Hold)
glock.Equipped:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
--UserInputService.MouseIconEnabled = false
mouse.Icon = "rbxassetid://8230755404"
h.Looped = true
h:Play()
end)
glock.Unequipped:Connect(function()
camera.CameraType = Enum.CameraType.Custom
mouse.Icon = [[]]
h.Looped = true
h:Stop()
end)
ClickDetector Script V
wait(.5)
local DoorModel = script.Parent
local Handle = DoorModel.DoorHandle
local Lock = DoorModel.Lock
local Locked = DoorModel.Locked
local Closed = DoorModel.Closed
local Show = DoorModel.ShowerLock
local ClickDetector = Handle.ClickDetector
local LockDetector = Lock.ClickDetector
local Side = DoorModel.Side
local TweenService = game:GetService("TweenService")
debounce = false
local function Move(Msg)
if Msg == "Open" then
TweenService:Create(Side,TweenInfo.new(1),{CFrame = Side.CFrame * CFrame.Angles(0,math.rad(90),0)}):Play()
script.Parent.door_open:Play()
elseif Msg == "Close" then
script.Parent.door_open:Play()
TweenService:Create(Side,TweenInfo.new(1),{CFrame = Side.CFrame * CFrame.Angles(0,-math.rad(90),0)}):Play()
elseif Msg == "Attempt" then
spawn(function()
for i = 1,6 do
wait(.15)
script.Parent.Attempt:Play()
end
end)
for i = 1,6 do
TweenService:Create(Side,TweenInfo.new(.05),{CFrame = Side.CFrame * CFrame.Angles(0,-math.rad(3),0)}):Play()
wait(.15/2)
TweenService:Create(Side,TweenInfo.new(.05),{CFrame = Side.CFrame * CFrame.Angles(0,math.rad(3),0)}):Play()
wait(.15/2)
end
end
end
LockDetector.MouseClick:connect(function()
if debounce then return end
debounce = true
Locked.Value = not Locked.Value
script.Parent.Lockedorunlocked:Play()
TweenService:Create(Show,TweenInfo.new(.4),{Orientation = Show.Orientation + Vector3.new(90,0,0)}):Play()
wait(.4)
debounce = false
end)
ClickDetector.MouseClick:Connect(function(plr)
if debounce then return end
print(plr)
debounce = true
if Locked.Value == true then
Move("Attempt")
else
if Closed.Value == true then
Move("Open")
wait(1.5)
Closed.Value = false
elseif Closed.Value == false then
Move("Close")
wait(1.5)
Closed.Value = true
end
end
debounce = false
end)