Basicly i am having troubles for the mobile players everything works on pc but not for mobile
for the camera
So the issue is basicly that after a mobile player have unequiped the tool the mobile player cant rotate their camera and i am not sure on how to fix this.
Tried some soultion witch didnt help but helped me to make this post. The solutions basicly helped me with just know that its not when a player dies its just that when u unequips the tool
The camerascript used inside the tool
repeat
wait()
until game.Players.LocalPlayer.Character ~= nil
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()
local Offset = Vector3.new(2, 2, 8)
local CamZoom = false
local CanCam = false
-------------------Cam Tween--------------------------
local FovIn = 40--How Far in u wanna zoom (Fov stands for Field Of View)
local FovOut = 70 ---The regular zoom (Fov stands for Field Of View)
local TweenTime = TweenInfo.new(0.5) --How long it will take for the tween
local ZoomIn = TweenService:Create(Camera, TweenTime, {FieldOfView = FovIn})
local ZoomOut = TweenService:Create(Camera, TweenTime, {FieldOfView = FovOut})
-------------------End of Cam Tween--------------------------
script.Parent.Equipped:Connect(function()
Camera.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
CanCam = true
CamZoom = true
Mouse.Button2Down:Connect(function()
if CamZoom == true then
ZoomIn:Play()
end
end)
Mouse.Button2Up:Connect(function()
if CamZoom == true then
ZoomOut:Play()
end
end)
local Humanoid = Character:WaitForChild("Humanoid")
local HumRootPart = Character:WaitForChild("HumanoidRootPart")
local CamAngleX = 0
local CamAngleY = 0
Humanoid.AutoRotate = false
local function PlayerInput(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Change then
CamAngleX -= InputObject.Delta.X
CamAngleY = math.clamp(CamAngleY - InputObject.Delta.Y * 0.4, -75, 75)
end
end
ContextActionService:BindAction("PlayerInput", PlayerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, function()
Camera = workspace.CurrentCamera
if CanCam == true then
Camera.CameraType = Enum.CameraType.Scriptable ---Setting the camera up so we can script it ourselfs
local StartCFrame = CFrame.new(HumRootPart.Position) * CFrame.Angles(0, math.rad(CamAngleX), 0) * CFrame.Angles(math.rad(CamAngleY), 0, 0)
local CamCFrame = StartCFrame:PointToWorldSpace(Offset)
local CamFocus = StartCFrame:PointToWorldSpace(Vector3.new(Offset.X, Offset.Y, -100000))
Camera.CFrame = CFrame.lookAt(CamCFrame, CamFocus)
local LookingCframe = CFrame.lookAt(HumRootPart.Position, Camera.CFrame:PointToWorldSpace(Vector3.new(0, 0, -100000)))
HumRootPart.CFrame = CFrame.fromMatrix(HumRootPart.Position, LookingCframe.XVector, HumRootPart.CFrame.YVector)
elseif CanCam == false then
Camera.CameraType = Enum.CameraType.Custom --Setting the cameratype to custom basicly the roblox camera core scripts
end
end)
end)
--------------------TO RESET------------------------------
local HumRe = Character:WaitForChild("Humanoid")
HumRe.Died:Connect(function()
CanCam = false
CamZoom = false
Camera.FieldOfView = FovOut
Camera.CameraType = Enum.CameraType.Custom
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end)
script.Parent.Unequipped:Connect(function()
ZoomOut:Play()
local Humanoid = Character:WaitForChild("Humanoid")
CanCam = false
CamZoom = false
Camera.FieldOfView = FovOut
Humanoid.AutoRotate = true
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end)
--------------------Mobile Buttons------------------------------
local Zoomed = false
function ZoomMobile(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then
if Zoomed == false then
Zoomed = true
ZoomIn:Play()
wait(0.2)
elseif Zoomed == true then
Zoomed = false
ZoomOut:Play()
wait(0.2)
end
end
end
while wait() do
if CanCam == false then
ContextActionService:BindAction("Zoom", ZoomMobile, false, Enum.KeyCode.ButtonR2)
ContextActionService:SetPosition("Zoom", UDim2.new(0.831, 0, 0.523, 0))
elseif CanCam == true then
ContextActionService:BindAction("Zoom", ZoomMobile, true, Enum.KeyCode.ButtonR2)
ContextActionService:SetPosition("Zoom", UDim2.new(0.831, 0, 0.523, 0))
end
end
The script i used to reset the camera when there is a character
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.AutoRotate = true
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Humanoid
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end)
I am not just asking for full sciprs just on what to reset and so so mobile players can rotate the camera