I’m currently making an FPS framework for a fun little project or whatever.
I’m running into an issue but before i tell you let me explain the structure a little
When the player joins the game they are assigned a default table (named framework) with their userID that is nil until a weapon is equipped. When the weapon is equipped a module script or client can update 3 things. The module, viewmodel, and currentSlot. Because its updated on the client, i have a remoteEvent to sync the server framework to the client version.
ISSUE
mi trying to retrieve a players framework using another remotefunction
The issue is that the returned framework is default and doesn’t include any of the updated information. (retrieved on a client)
This is strange because when i print the servers version it is correct and updated, but just trying to retrieve that has become a struggle.
here is some code examples
SERVER:
local playerFrameworks = {}
local function createPlayerFramework(player)
playerFrameworks[player.UserId] = {
inventory = {
'AR-15', -- Primary
'Brick' -- Secondary
-- More items can be added here
},
module = nilVALUE,
viewmodel = nilVALUE,
currentSlot = nilVALUE
}
end
local function updateFramework(player, playerFramework, viewmodelName)
local framework = playerFrameworks[player.UserId]
if framework then
framework = playerFramework
framework.viewmodel = viewmodelName
print(framework)
end
end
UpdateFrameWork.OnServerInvoke = function(player)
return playerFrameworks[player.UserId]
end
As you can see it correctly returns the framework, creates new ones, and updates it.
CLIENT TRYING TO RETRIEVE:
if input.KeyCode == Enum.KeyCode.One then
if db then return end
frameWork = UpdateFrameWork:InvokeServer(player)
db = true
if frameWork.currentSlot ~= 1 then
print("loading 1st slot, which we dont have currently")
print(frameWork.currentSlot)
viewModelController:loadSlot(frameWork.inventory[1], 1)
frameWork.currentSlot = 1
elseif frameWork.currentSlot == 1 then
viewModelController:dequipSlot()
frameWork.currentSlot = nilVALUE
end
task.wait(.5)
db = false
end
As you can see better the issue is that if i currently have equipped slot 1, and i press 1 to DEequip it, it prints that the value of currentSlot is actually “NilString” (my default value for it) so it runs the 1st if statement meaning I’m just equipping the same weapon over and over again. aka the table is not correctly updated somehow.