Help accessing PlayerModule in a character script

Note: Server can’t access to playerScripts

its from the client. Im able to get the module, its the methods that dont work. The error is with the Module script not with my script trying to access it.

Should say to Bug-Support group or wait for someone posts to bug category if it was came from Roblox’s script.

Or just copy and modify.

Yeah ive seen that post before i made this one. There wasn’t an solution to it though. I thought about bug reports but im not sure that anything wrong is happening. Im sure this is just me misunderstanding how that particular module works.

Or didn’t create instance before by using “.new”.

The module script returns a new instance at the last line of the script. when you require the module it will do that automatically.

You need to define self.cameras in your function first before returning it.

This is a module script. Self is defined in the constructor as a metatable. You dont need to define it in every function. the other modules parented this script do the same thing with no errors when required.

Create instance and call camera from that instance.

Or use [function](created instance)

Can you do that?

I meant did you use a period in your script that calls the function? The function :GetCameras() in the module script uses a colon, meaning it accepts “self” as its first parameter, so when you call it from wherever you call it, you need to either specify self by calling it with a colon or calling it with a period and just adding self as the first argument.

The script seems to be erroring because “self” doens’t exist, which means it’s not being passed into the function when you call it. Can you show your code that uses this module script and calls the function?

2 Likes

I didn’t know that, but i do remember trying it with the colon but the return value is an empty table.
in my script i require the PlayerModule and in a function i have PlayerModule:GetCameras() which prints out to an empty table.

Replace bolded string to created instance.

I dont get what you mean. What would i replace it with?

Okay, more laconic one.

--Create instance with
local pm = PlayerModule.new()
--or
local pm = require(PlayerModule)
--Then use
pm:GetCameras()
--and self will work

Note

function dsc:IsbookFound(pid,book)
--↓
ds.IsbookFound(dn,pid,dn)
function dsc.IsbookFound(pid,book)
--↓
ds.IsbookFound(pid,dn)

thats what i did. Just replace PlayerModule from my code with pm from urs. I only named it that way for convenience.

Is this works?

local LocalPlayer = game:GetService("Players").LocalPlayer
local Cameras = require(LocalPlayer.PlayerScripts.PlayerModule):GetCameras()

Yeah someone else told me about that already but no not exactly. If you try it in studio you get an empty table when you print. Which shouldnt be the case it should have stuff in it.

Can you print LocalPlayer then?

If couldn’t print LocalPlayer(Other than unknown and Player named Player), it was the root of problem.

PS: Have you checked this?

When you require() the PlayerModule ModuleScript, it returns the result of the PlayerModule.new() function, or a new PlayerModule instance:
image

In the .new() function, the PlayerModule sets the properties .cameras and .controls to the CameraModule and ControlModule.
image

When you run the code with the colon and all, it runs this function, returning whatever is stored in the .cameras index:
image

If we look at the CameraModule ModuleScript to see what it actually returns, we can see that it returns an empty table if this “FFlagUserRemoveTheCameraApi” is evaluated as true.
image

In other words, maybe the problem is that this FFlagUserRemoveTheCameraApi thing is being evaluated as true for some reason. I haven’t really looked through the scripts though so I don’t exactly know how you could get the result you’re looking for, but you might be able to follow this variable and see what you need to change at some point along that path.

1 Like

ty ty that did it. Yeah idk what that is either so i just said YOLO and set
local cameraApi = cameraModuleObject
worked perfectly. Thanks

1 Like