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.
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
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
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?
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.