How to update ModuleScript's values?

Any idea how to update value in ModuleScript across all clients?
My scripts are:
ModuleScript

Tune = {}

Tune.T_Boost = 15

return Tune

LocalScript1

local car = script.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local Tune = _Tune

frame.T_Boost.FocusLost:Connect(function()
	if tonumber(frame.T_Boost.Text) then
		Tune.T_Boost = tonumber(frame.textBox.Text)
	else
		frame.T_Boost.Text = "Invalid Value"
	end
end)

frame.Apply.MouseButton1Click:Connect(function()
	if frame.T_Boost.Text == "Invalid Value" then
		return
	else
		car.DriveSeat.RemoteEvent:FireServer("Apply", Tune)
		gui:Destroy()
	end
end)

Script1

local car = script.Parent.Parent.Parent
local _Tune = require(car["A-Chassis Tune"])

script.RemoteEvent.OnServerEvent:Connect(function(F, Tune)
	if F == "Apply" then
		for i, v in pairs(Tune) do -- this doesnt update the value on the client side, why?
			_Tune[i] = v
		end
	end
end)
1 Like

You’re not setting the value on the client, you’re setting it on the server.

ModuleScripts don’t replicate. The client and server each have their own separate space.

I would recommend adding a OnClientEvent on the client to receive feedback from the server, and using :FireAllClients() on the server to fire to every client.

Client:

local car = script.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local Tune = _Tune

frame.T_Boost.FocusLost:Connect(function()
	if tonumber(frame.T_Boost.Text) then
		Tune.T_Boost = tonumber(frame.textBox.Text)
	else
		frame.T_Boost.Text = "Invalid Value"
	end
end)

frame.Apply.MouseButton1Click:Connect(function()
	if frame.T_Boost.Text == "Invalid Value" then
		return
	else
		car.DriveSeat.RemoteEvent:FireServer("Apply", Tune)
		gui:Destroy()
	end
end)
-- NEW:
car.DriveSeat.RemoteEvent.OnClientEvent:Connect(function(F, Tune)
	if F == "Apply" then 
		for i, v in pairs(Tune) do 
			_Tune[i] = v
		end
	end
end)

Server:

local car = script.Parent.Parent.Parent
local _Tune = require(car["A-Chassis Tune"])

script.RemoteEvent.OnServerEvent:Connect(function(F, Tune)
	if F == "Apply" then
		for i, v in pairs(Tune) do -- this doesnt update the value on the client side, why?
			_Tune[i] = v
		end
		-- NEW:
		script.RemoteEvent:FireAllClients(F, Tune);
	end
end)

thats the first time ill ever be using remote functions so if anything goes wrong ill report to you, do you mind?

You should look at the new reply, I updated it. Realized you were asking for smth else.

1 Like

sorry for late response but i couldnt test it out

also i forgot to mention that the car has 2nd localscript which handles the physics on client, so i went the remotefunction way. the thing is that i think that i might have messed something up cause it doesnt work the way it should
so what i did is:
LocalScript1

frame.Apply.MouseButton1Click:Connect(function()
	car.DriveSeat.Manage.RemoteEvent:FireServer("Apply", T)
end

LocalScript2 - this script runs whenever a player enters the seat because its cloned with gui so it runs from the beginning. why i decided to do it this way is because your method would only work for players that were in the game when the event fired

local _Tune car.DriveSeat.RemoteFunction:InvokeServer(require(car["A-Chassis Tune"])

Script1

script.Apply.OnServerInvoke = function(player, T)
	for i, v in pairs (_Tune) do
		T[i] = v
	end
	return T
end

nevermind, there was a typo. it seems to be working on client. will check rq if it does work on other clients
edit: yup, everything works as intended, your previous solution was correct, thanks

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