#Module script not getting/setting information correctly

36 messages · Page 1 of 1 (latest)

waxen linden
#

So I have quite a strange script at the moment. A player inputs their groupID and then that groupID is then sorta "bound" to the user with the following code:

function GroupStorage.setSelectedGroupId(playerUserId, groupId)
    playerGroupData[playerUserId] = groupId
end

However, whenever I try and return this information to a different script with the following function, it seems to output "nil" instead of the "updated/bound" information (that being the groupID) and idk why:

function GroupStorage.getSelectedGroupId(playerUserId)
    return playerGroupData[playerUserId] or nil 
end

So I was wondering if there was a way for me to kinda read this information while I test my game to see if the information is being correctly bound to the data or not. Sorry if I am being a bit nonsensical- I am quite noobish. I'll be happy to explain things better.

#

I'd like to point out that the above two functions are in a module script in replicated storage. When I try and run this code, for example, in a different script, "nil" is outputted:

local selectedGroupId = GroupStorage.getSelectedGroupId(player.UserId)
print("Your selected group is" .. selectedGroupId)

It would just print "Your selected group is" nil

#

Despite the fact that in a different script, I have this function to "update" the information:

GroupStorage.setSelectedGroupId(player.UserId, group.Id)
print("Group ID selected and stored: ", group.Id)

Where it would correctly print out a "Group ID selected and stored: xxxxxxxx"

#

So there appears to be an issue with the way the module script handles the information and how other scripts retrieves this information. So does anyone know why it aint working?

#

Module script not getting/setting information correctly

wintry spindle
#

Try to add more debug

#

Whenever you use that function in the module print player name and group id @waxen linden

#

To see if everything called correctly

waxen linden
#

It seems that the error is to do with getting that information from the module. Here is the new part of the script which deals with debugging of the "setting" the information:

function GroupStorage.setSelectedGroupId(playerUserId, groupId)
    playerGroupData[playerUserId] = groupId
    print("The group " .. playerGroupData[playerUserId] .. " is now bound to player")
end

As we can see here, we will get a line saying "The group xxxxxxxx is now bound to player", showing that playerGroupData[playerUserId] now successfully contains the group information. Here is an image showing this work in the code:

#

The second line specifically is from the function (the other two are debugging lines from the script setting the information)

#

Now in my next area of this module script, we have the function which deals with the debugging of the "getting" the information:

function GroupStorage.getSelectedGroupId(playerUserId)
    if playerGroupData[playerUserId] then
        print("The group ID you are trying to retrieve is " .. playerGroupData[playerUserId])
    end
    return playerGroupData[playerUserId]
end

As we can see here, we will be, once again, notified of the value that playerGroupData[playerUserId]) contains by printing it in a sentence, and then it will return this EXACT value when it is requested. However, that printline is not being outputted, which makes me think that the request function is not correctly calling this function this information. But I do not understand why.

#

Here is the line of code, in a different script, which should be requesting the information:

local selectedGroupId = GroupStorage.getSelectedGroupId(player.UserId)
print("Selected Group ID from storage: ", selectedGroupId)

I do not know why this is not working because this "getSelectedGroupId" function is not correctly operating. I do not know what mistake I am getting.

#

This is what gets outputted which does not make sense. Can anyone see why this is happening?

chrome mural
#

and setting it from a server script?

waxen linden
#

Uh so a local script is setting the "information" to the module script (as that is where the information is stored ig). Then another different local script is accessing the module script to "retrieve" that information. So basically:
Local Script 1 -----> Setting Information -----> Module Script
Local Script 2 -----> Request Information ------> Module Script ------> Sending Information ------> Local Script 2

#

i guess that explains it badly

#

but thats the premise

chrome mural
#

it should work if its the same player

waxen linden
chrome mural
#

lleme test something rq

waxen linden
waxen linden
#

I am unfortunately going to sleep so I'll take any advice tomorrow. (Any other person reading this- feel free to chip in some advice too)

#

Goodnight lad

#

and thanks in advance

chrome mural
#

this works for me

waxen linden
#

I am so confused this should be working but it isnt

#

lowkey I hate problems like this- simple shit that should work clearly but doesn't.

#

because in this other script here, the "local selectedGroupId = GroupStorage.getSelectedGroupId(player.UserId)" DOES work. It does correctly

#

Oh wait I think I figured it out.

#

Yeah it was cuz the "get" function was not correctly placed in a function, meaning it would not pick up any new changes

#

Oh well atleast I figured that out