This is pretty self explanatory based off the title
valuesModule.findValue() from the server works as expected, but returns nil when called from the client.
Client script:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage:WaitForChild("Remotes")
local combatEvent = remotes:WaitForChild("CombatEvent")
local modules = ReplicatedStorage:WaitForChild("Modules")
local valuesModule = require(modules:WaitForChild("Values"))
local player = game.Players.LocalPlayer
UserInputService.InputBegan:Connect(function(input, processed)
local equipInput = valuesModule.findValue(player, "equipInput")
local m1Input = valuesModule.findValue(player, "m1Input")
local blockInput = valuesModule.findValue(player, "blockInput")
if not processed then
if input.UserInputType.Name or input.KeyCode.Name == equipInput then
combatEvent:FireServer("equip")
elseif input.UserInputType.Name or input.KeyCode.Name == m1Input then
combatEvent:FireServer("m1")
elseif input.UserInputType.Name or input.KeyCode.Name == blockInput then
combatEvent:FireServer("block")
end
end
end)
Module script:
local playerData = {}
local module = {}
function module.addPlayer(player)
playerData[player.UserId] = {
--Bools
equipped = false,
blocking = false,
parrying = false,
hitboxVisuals = true,
--Strings
weapon = "testSword",
--Keybinds
blockInput = "F",
equipInput = "E",
attackInput = "MouseButton1"
}
end
function module.removePlayer(player)
playerData[player.UserId] = nil
end
function module.findValue(player, value)
return playerData[player.UserId][value]
end
function module.changeValue(player, value, newValue)
playerData[player.UserId][value] = newValue
end
return module
And yes, the values are inserted from the server I promise.
Thatâs because when you required on the server all the information in that module script is essentially server level. When you require on the client you canât see server updates on the module script because info was added on the server level. Idk if this makes sense but Iâm not the best at explaining
it probably doesnât get replicated from the server, youâd need to have a remote from the server to the client telling it when a new player is created so it can recreate that information on the client
thatâs for instances (except the ones in ServerScriptStorage, ServerStorage etc.), changes in code donât just get replicated unless you make them replicate because roblox wouldnât even know if something is supposed to replicate or not
My worry is that this will be very costly. A remote event will fire about 3 times on average every second for each player. At this point, I might as well have a folder of values in the player right?
As many other developers stated on their replies, modules are limited to their specific script levels. Data on the server will not be the same as in the client, because the memory is different on both.
Thatâs why it wonât work.
But what you could do is to use module.addPlayer (in the client) as soon as the client joins the game, and modify the values you need by asking the server with a RemoteFunction for all the values necessary (i.e. RemoteFunction:InvokeServer({"weapon","blockInput","equipInput","attackInput","hitboxVisuals"})) and in the server just loop through this table and return all the values as a table to the client, then the client loops through the returned table and sets the values in the client data.
server sided movement scripts (like Chickynoid) send 20 remotes per second to everyone, 3 per second is not that much, although Chickynoid uses unreliable remotes to do it
Right. I am unfortunately cursed with a neurotic question in my head, âis this the most optimized way?â And until I am satisfied that I am, it lingers in my head indefinitely bothering me.
Edit: I just realized this would actually save me a lot of remote event firing because I donât have to fire one for each input of the playerâŚ