Hello, I am a little perplexed again and trying to understand something and grow my knowledge.
I have a module script located in Replicated Storage and under the module script, I create Value Objects to store data I need during the game session that does not get saved to a datastore. It looks like this:
When the player joins, I create a Folder for that player underneath the module with this function:
function sessionData.playerSetup(player)
local newFolder = Instance.new("Folder")
newFolder.Name = tostring(player)
newFolder.Parent = script
sessionData.addPotionTimer(player)
end
After that I add the Value Object like so:
function sessionData.playerRemove(player)
local storageName = tostring(player)
local thisStorage = script:FindFirstChild(storageName)
thisStorage:Destory()
end
And it looks like this:
OK, now the setup is done, lets move to the problem. In another script I am trying to reference that folder and value object and set its value. I am doing it like this:
local replicatedStorage = game:GetService("ReplicatedStorage")
local sessionData = require(replicatedStorage:WaitForChild("SessionData"))
function potionTimer.setTimer(player,potion)
local thisPlayer = tostring(player)
local playerFolder = replicatedStorage.sessionData:FindFirstChild(thisPlayer)
local thisTimer = playerFolder:FindFirstChild("PotionTimer")
thisTimer.Value = potion.duration
end
When i run this, i get an error that says:
[ReplicatedStorage.SessionData:11: attempt to call field ‘addPotionTimer’ (a nil value)]
If I simply change the line that reads:
local playerFolder = replicatedStorage.sessionData:FindFirstChild(thisPlayer)
TO
local playerFolder = replicatedStorage.SessionData:FindFirstChild(thisPlayer)
then it will work. All I did is capitalize the first S of SessionData which is the module scripts actual name inside ReplicatedStorage. The lowercase “s” of sessionData is the variable I set at the top of the script using require().
The perplexing part is, I have done this same sort of thing in other script in this game and it is able to use the variable. I prefer to use the variable defined because if i move the script, it is of course much easier to simply change the defined variable instead of combing through script changing every reference.
Thanks for taking the time to read thorough all of this, as I said I am trying to understand this inconsistency behavior. I have something very similar to this working in another script and don’t understand why its not working here.