How would I change the camera script once you enter a new area

I am making a game that has multiple areas with in it. To keep it simple lets just say there are outdoor and indoor areas.

I am attempting to make it to where the camera works differently in two different areas. So outside its free cam, while inside its a top down view. It isn’t different camera angles, its entirely different systems.

I’ve attempted to make a script that enables and disables the scripts, but scripts in the workspace cant access anything in StarterPlayerScripts (where my camera scripts are).

All I really need to know is how I can get a script to access scripts in StarterPlayerScripts. If anyone can provide useful information that would be perfect as google isn’t serving me well, and neither are any posts on the forum.

StarterPlayerScripts are located in

game.Players[PlayerNameHere].PlayerScripts

So all you need to access the StarterPlayerScripts is player’s name

Okay! That was pretty quick. I am wondering this is specific to one playername. Scripts can get the name of a player and insert them into the script when its ran right?

Yes, all players have different PlayerScripts (Their inside is same but they are run in different locations) and yes for the second question too you can get a player’s name by scripts

Thank you so much! Im not really well versed in the more technical side of scripting (if you can call it that). So thanks for assisting.

You usually are able to put scripts both into StarterGui, StarterCharacterScripts, or StarterPlayerScripts

Thank you too! Ill try this along with HeYSeNHeLIO_TR’s suggestion

So, I came up with this script. But it returns with an error.

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		game.Players[player.name].PlayerScripts.CameraScript.enabled = false
	end
end)

Error is: PlayerScripts is not a valid member of Player “Players.Xenaside”

I also should mention that I tried manually enabling and disabling the camera scripts while playing and the other script never takes effect when I enable it. The only reason I can think of this being an issue is that the other script needs to be ran or called. But I’m not entirely sure on how I would go about doing this.

I just realized that you can’t reach “PlayerScripts” folder by normal scripts, you have to use local scripts to reach it.

But you can use RemoteEvents too, just create a RemoteEvent inside ReplicatedStorage and paste this code into the script.Parent.Touched function:

if part.Parent:FindFirstChild("Humanoid") then
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local Event = ReplicatedStorage:WaitForChild("RemoteEvent")
    local Player = game.Players:GetPlayerFromCharacter(part.Parent)
    local PlayerName = Player.Name
    Event:FireClient(PlayerName, "enable")
end

and create a LocalScript inside StarterPlayerScripts and paste this code here:

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local Event = ReplicatedStorage:WaitForChild("RemoteEvent")
    local CameraScript = script.Parent:WaitForChild("CameraScript")
    Event.OnClientEvent:Connect(function(PlayerName, EnableOrDisable)
        if EnableOrDisable == "enable" and PlayerName = game.Players.LocalPlayer.Name then
            CameraScript.Enabled = true
        elseif EnableOrDisable == "disable" and PlayerName = game.Players.LocalPlayer.Name then
            CameraScript.Enabled = false
        end
    end)

these scripts may not work first try, I didn’t test it but they should enable the CameraScript if they work and you can change Event:FireClient(PlayerName, "enable") toEvent:FireClient(PlayerName, "disable") to disable the CameraScript

1 Like

Getting red underlines at “= game.Players.LocalPlayer.Name then”. Specifically the equals sign and then.

My bad put == instead of =

30 letters limit

1 Like

Alright thanks dude. I would of never gotten this far without you.

Okay final thing, i know im asking alot. But in the script inside of the part it says “unable to cast value to object”. At line 8. Any idea of why this is happening?

Can you send the full script

.

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		local ReplicatedStorage = game:GetService("ReplicatedStorage")
		local Event = ReplicatedStorage:WaitForChild("RemoteEvent")
		local Player = game.Players:GetPlayerFromCharacter(part.Parent)
		local PlayerName = Player.Name
		Event:FireClient(Player.Name, "disable")
	end
end)

Its a little hacky cause I just put your script into the script I have.

Try replacing :FireClient with :FireAllClients

Doesnt fire all clients mean it will fire for everyone in the game?

But the client code checks if the PlayerName is equal to LocalPlayer’s name so there should be no problem I think

Okay! Well it worked, really well actually! Ill get to fully applying this. Thanks for all the help my guy.

You’re welcome :slight_smile: