Client Cannot Interact With Values Module

This is pretty self explanatory based off the title :sob:

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.

3 Likes

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

1 Like

Roughly. What’s a fix?

character lomit

1 Like

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

1 Like

But I thought everything that happens on the server happens on every 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.

1 Like

Remote functions are unreliable, no?

1 Like

The opposite, they are reliable if set-up properly, as they yield the client thread until the server gives a response.

Alright, I will look into it and mark it as the solution if it works out.

1 Like

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…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.