I want to access the camera module object created by PlayerModule so i can use it. However when i try to use the modules GetCameras() method i get an empty table or sometimes an error saying that self is nil.
line 21 is return self.cameras
anyone got experience trying to mess with these?
here is the Module script that loads automatically on run time. ( for those who think that the issue is with the module script)
--!strict
--[[
PlayerModule - This module requires and instantiates the camera and control modules,
and provides getters for developers to access methods on these singletons without
having to modify Roblox-supplied scripts.
2018 PlayerScripts Update - AllYourBlox
--]]
local PlayerModule = {}
PlayerModule.__index = PlayerModule
function PlayerModule.new()
local self = setmetatable({},PlayerModule)
self.cameras = require(script:WaitForChild("CameraModule"))
self.controls = require(script:WaitForChild("ControlModule"))
return self
end
function PlayerModule:GetCameras()
return self.cameras
end
function PlayerModule:GetControls()
return self.controls
end
function PlayerModule:GetClickToMoveController()
return self.controls:GetClickToMoveController()
end
return PlayerModule.new()
Did you use a “.” instead of a “:”? If self is what doesn’t exist then maybe you called the function with a “.”, which doesn’t pass self into the function.
its the default playerModule script that every player spawns with in their playerScripts folder. Load a game in studio and copy / paste it.
--!strict
--[[
PlayerModule - This module requires and instantiates the camera and control modules,
and provides getters for developers to access methods on these singletons without
having to modify Roblox-supplied scripts.
2018 PlayerScripts Update - AllYourBlox
--]]
local PlayerModule = {}
PlayerModule.__index = PlayerModule
function PlayerModule.new()
local self = setmetatable({},PlayerModule)
self.cameras = require(script:WaitForChild("CameraModule"))
self.controls = require(script:WaitForChild("ControlModule"))
return self
end
function PlayerModule:GetCameras()
return self.cameras
end
function PlayerModule:GetControls()
return self.controls
end
function PlayerModule:GetClickToMoveController()
return self.controls:GetClickToMoveController()
end
return PlayerModule.new()
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.
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.
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.
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?
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.