How to only change the CurrentCamera for one player

I’m having an issue in my game where it changes the CurrentCamera FieldofView for all players, except I only want it to change for the one that touches the part. I am a new scripter so please explain things to me in simple format


Any help is appreciated

1 Like

Set the run context of the script to client

1 Like

Can you explain how?
character li

1 Like

Click the script, drop down the run context property, and click client.

1 Like

i think you can only change camera in a local script

1 Like

It is a local script I am working with not a normal script

1 Like

Change it to a script, then make the run context client. Local scripts do not run in the workspace.

1 Like

Should the script go in StarterPlayer like all my others?

1 Like

It doesn’t necessarily matter, you can keep it in the workspace if you want to.

1 Like

the camera script can go to StarterGui

1 Like

Thanks so far for the help, now the issue I am having is that it is telling me that the part you touch “Despair” is not a valid member of Worskspace “Workspace”

image
(It is in Workspace)

1 Like

In the script, use :WaitForChild("Despair") to reference it. You should always use WaitForChild to get objects.

1 Like

After the touched event, fire a RemoteEvent to the client which tells it to tween it’s camera. You can’t edit the camera on the server (or it won’t work as you want) and you can’t detect .Touched on the client. This is probably the only solution.

4 Likes

So since I am a new scripter I honestly have no idea if I am doing this right or wrong, I decided to watch a couple tutorials to get grasps of RemoveEvents but it still doesn’t work; probably because I am using it wrong.


This is what I have made, if you could help it would be appreciated <3

1 Like

You need to pass the player as the first parameter of FireServer.

1 Like

Can you explain how?
Sorry I am new and I just don’t understand

1 Like

RemoteEvents, when fired from the server, can either be fired to all clients, aka all players, or to one specific player, to fire for a player, do: remote:Fire(player), for all players, do: remote:FireAllClients(). You need one player so do the first option/ If you don’t understand what are servers and clients please do tell me so I can explain them.

1 Like

I know what servers and clients are but I am just slightly confused on how to incorporate it into the scripting.
image
Is this the correct format then for firing for the player?

image
Would I have to put player within the function parameter as well in the other script?

1 Like

LocalScript in StarterPlayerScripts*

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer

local currentCamera = workspace.CurrentCamera
local despair = workspace:WaitForChild("Despair")
local db = false

despair.Touched:Connect(function(hit)
    if db or
		not hit.Parent or
		not hit.Parent:FindFirstChildOfClass("Humanoid") or
		not Players:GetPlayerFromCharacter(hit.Parent)
	then
		return
	end

	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player ~= localPlayer then
		return
	end

	db = true
	local tween = TweenService:Create(currentCamera, TweenInfo.new(20, Enum.EasingStyle.Linear), {FieldOfView = 50})

	tween:Play()
	tween.Completed:Connect(function()
		player:Kick("message")
	end)
end)

I read the question wrong for my first reply mb

1 Like
  • Make a remote event. Place it in replicated storage
  • Make a localscript. Place it in StarterPlayerScripts.
  • Add the following code:
local RemoteEvent = <pathtoremoteevent>
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local TweenS  =  game:GetService("TweenService")

RemoteEvent.OnClientEvent:Connect(function(FOV)
    TweenS:Create(Camera, <TweenInfo>, FOV):Play()
end)

Remove the tween fov line from the global script and fire the event on the same place with the value.

Remote:FireClient(player, FoV)

Usually Camera and GUI related work should be handled by the client and not the server.

Quick explanation of a RemoteEvent:

  • Firing an event is done by:
event:FireClient(<PlayerParameterRequired>)
event:FireServer().

Server is one but clients (Players) are many, so you need to specify which one to be sent.
You can also use event:FireAllClients() if you want it to be sent to all clients.
As to getting a requested event is done by:

event.OnClientEvent:Connect(function(<AllParametersSent>)
end)

--or for server:

event.OnServerEvent:Connect(function(<PlayerWhoSent>, <AllParametersSent>)
end)

Hope I’ve explained it clearly.

1 Like