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:

local 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:

-- This is inside a normal Script in ServerScriptService
game.Players.PlayerAdded:connect(function(player)
    local getCamera = script:WaitForChild("GetCamera"):Clone() --Already created RemoteFunction
    getCamera.Parent = player
    getCamera:WaitForChild("LocalScript").Disabled = false --Script inside RemoteFunction
end)

-- This is what's inside the LocalScript in the RemoteFunction (separate script)
function script.Parent.OnClientInvoke()
    print("Getting camera...") --> Doesn't print anything when invoked
    return game.Workspace.CurrentCamera
end

-- This is inside a normal Script in StarterCharacterScripts (separate script)
local player = game.Players:GetPlayerFromCharacter(script.Parent)
print(player:FindFirstChild("GetCamera") ~= nil) --> prints true (so it exists!)
local camera = player:FindFirstChild("GetCamera"):InvokeClient(player)
print("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:

local 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