Change playermodule mid game

so i have 2 forked versions of the default player module which just changes the movement a little bit.
team 1 will have 1 forked version and team 2 will have a different forked version
if the teams are changing mid game, how would i switch out the player modules

1 Like

To set up a similar hypothetical use case as the one you described, I’ve assumed the two ModuleScripts are set up like this:

image

-- ModuleScript 'Team A'
local module = {}
module.WalkSpeed = 20

return module
-- ModuleScript 'Team B'
local module = {}
module.WalkSpeed = 16

return module

You can then store the necessary module like this:

-- Client code
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Player = game:GetService('Players').LocalPlayer
local teamModule = require(ReplicatedStorage.Modules[Player.Team.Name])

-- Re-assign the teamModule when the player changes teams
Player:GetPropertyChangedSignal('Team'):Connect(function()
	local module = ReplicatedStorage.Modules:FindFirstChild(Player.Team.Name)
	
	if module then
		teamModule = require(module)
	end
end)

print(teamModule.WalkSpeed)
2 Likes

this works and all, but remember that roblox adds the default PlayerModule whenever a player joins, so these 2 modules would be counteracting with eachother

You can require the default PlayerModule and replace the functions to modify it.

1 Like

I’m not sure why the PlayerModule would interfere with this. Both ModuleScripts and the LocalScript requiring them have no connections to the PlayerModule. Could you give an example where this would become an issue?

1 Like

nah everything works its all good we :up:

1 Like

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