I did this with a LocalScript. This is my code:
local gui = game:GetService("StarterGui") while true do if gui.ScreenGui.Frame.Visible == true then game.StarterPlayer.CameraMaxZoomDistance = 10 game.StarterPlayer.CameraMinZoomDistance = 10 game.StarterPlayer.CameraMode = "Classic" wait(1) end if gui.ScreenGui.Frame.Visible == false then script.Parent.Parent.CameraMode = "LockFirstPerson" wait(1) end end
First of all, StarterPlayer
refers to a service that allows you to set default properties for the player object. StarterGui
is the same thing except it sets default properties for the PlayerGui object. So if you want to change these objects during run-time, instead of StarterPlayer
use local player = game.Players.LocalPlayer
and instead of StarterGui
use local gui = player:WaitForChild("PlayerGui")
.
local player = game.Players.LocalPlayer local gui = player:WaitForChild("PlayerGui") while true do if gui.Frame.Visible == true then player.CameraMaxZoomDistance = 10 player.CameraMinZoomDistance = 10 player.CameraMode = "Classic" wait(1) end if gui.Frame.Visible == false then script.Parent.Parent.CameraMode = "LockFirstPerson" -- Did you mean player.CameraMode = "LockFirstPerson"? wait(1) end end
Now, as for the changing camera mode when you touch something you need to use the Touched
event . Not sure how the script you made above relates to what you want to do, but changing the camera mode when a part is touched would look something like this in a LocalScript:
local part = workspace.Part -- set this to whatever part you would like to be touched local player = game.Players.LocalPlayer part.Touched:Connect(function(touch) -- If the touched parts parent is the player character (would have the same name as the player) if touch.Parent.Name == player.Name then player.CameraMode = "LockFirstPerson" end end)
However you would like to integrate what you have made so far with the touched event is up to you. Good luck!