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

I need the camera mode to change when you touch something may someone please help?

Asked by 4 years ago

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

1 answer

Log in to vote
0
Answered by
blazar04 281 Moderation Voter
4 years ago
Edited 4 years ago

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!

1
It says ScreenGui isn't a valid member of PlayerGui techingenius -82 — 4y
0
Oh my bad, I needed to change the if statement to "if gui.Frame.Visible..." I changed the script should be good blazar04 281 — 4y
Ad

Answer this question