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
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”
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.
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.
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.
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)
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.
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)