Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Retrieving CurrentCamera from a normal Script?

Asked by
nilVector 812 Moderation Voter
8 years ago
Edited 8 years ago

I know that you can retrieve the CurrentCamera from a LocalScript by doing this:

1local camera = game.Workspace.CurrentCamera

However, I want to be able to get the CurrentCamera in a normal Script, specifically for one that is in StarterPlayer > StarterCharacterScripts.

I have tried using a RemoteFunction to retrieve it. This is the method that I used:

01-- This is inside a normal Script in ServerScriptService
02game.Players.PlayerAdded:connect(function(player)
03    local getCamera = script:WaitForChild("GetCamera"):Clone() --Already created RemoteFunction
04    getCamera.Parent = player
05    getCamera:WaitForChild("LocalScript").Disabled = false --Script inside RemoteFunction
06end)
07 
08-- This is what's inside the LocalScript in the RemoteFunction (separate script)
09function script.Parent.OnClientInvoke()
10    print("Getting camera...") --> Doesn't print anything when invoked
11    return game.Workspace.CurrentCamera
12end
13 
14-- This is inside a normal Script in StarterCharacterScripts (separate script)
15local player = game.Players:GetPlayerFromCharacter(script.Parent)
16print(player:FindFirstChild("GetCamera") ~= nil) --> prints true (so it exists!)
17local camera = player:FindFirstChild("GetCamera"):InvokeClient(player)
18print("Retrieved camera") --> doesn't print anything; rest of the script doesn't execute

So it is apparent that when I invoke the client to retrieve the CurrentCamera, it yields the script right there. It doesn't even give any errors or anything. The script just pauses there. Is it possible to retrieve CurrentCamera from a normal Script at all, or am I doing something wrong in my method?

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

You CAN'T retrieve a player's CurrentCamera from a server script. Also, the way to retrieve CurrentCamera is by:

1local camera = workspace.CurrentCamera
0
Oh, I knew that. I have no idea why I wrote "LocalCamera" instead of "CurrentCamera". I fixed it. Anyways, thanks for the response. nilVector 812 — 8y
0
if u do workspace.CurrentCamera in a normal script though, it returns the **SERVER'S** camera which you probably dont need AdamFunMaker 35 — 8y
Ad

Answer this question