Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to change current camera outside of player scripts?

Hey I'm really new to scripting and I'm trying to make a part that disappears only for the player that steps on it and no one else, how do I do that? I don't know how to use current camera from not inside the player scripts. Can someone help with this issue? Thanks.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then 
		workspace.CurrentCamera.FieldOfView = 10
	end
end)

1 answer

Use Remote Events. You probably don't know, so I'll try my best to explain. workspace.CurrentCamera requires a client to manipulate the camera. (Sounds weird considering you can't put a localscript inside workspace). The only logical place to place localscripts is in StarterGui, StarterPlayerScripts and StarterCharacterScripts. I'll be using StarterCharacterScripts.

So basically, put a remote event in ReplicatedStorage, replace your localscript with a serverscript, and put a localscript in StarterCharacterScripts.

Server Script

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent) --This sounds weird, so I'll break it down. We're getting the player from the character. NPCs do not have a player, so you wanna differentiate them between the two.
	if plr then
		game.ReplicatedStorage.RemoteEvent:FireClient(plr) --The 1st parameter is ALWAYS a specific player. If you do not put it down, the script will not work.
	end
end)

Local Script

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() --You pass your tuple arguments here. But since we haven't passed any, we'll leave it blank.
	workspace.CurrentCamera.FieldOfView = 10
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.