Dictionary contents not visible to local script

Module script located in ReplicatedStorage:

local Players = game:GetService('Players')

local PlayerDictionary = {}

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		PlayerDictionary[Character.Name] = {
			['Parrying'] = false,
			['Blocking'] = false,
			['Disabled'] = false,
			['Attacking'] = false,
			['Ragdolled'] = false,
		}
		
	end)
end)

return PlayerDictionary

Server-sided script located in ServerScriptService:

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local PlayerDictionary = require(ReplicatedStorage.PlayerDictionary)

task.wait(3)

print(PlayerDictionary)

Local script located in StarterPlayerScripts:

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local PlayerDictionary = require(ReplicatedStorage.PlayerDictionary)

task.wait(3)

print(PlayerDictionary)

My output:

Expected:
I expected the local script to return the same value as the server script. Why is the table empty for only the local script but not for the server script?

Playeradded and characteradded event don’t work in local scripts.

So how would you go about fixing this issue?

When you require a ModuleScript on the server it sort of creates a single copy that all the server scripts then access the same copy. The client and server have their own different copies, so obviously changes the server makes wont replicate to the client.

Anyway, LocalScripts don’t run until the game has loaded (Unless they are within ReplicatedFirst), so your player will have joined before your local copy of the ModuleScript listens for players to join.

Solution: Hardcode the module to manually create its own copy of the local player, use RunService:IsServer or :IsClient to do this.

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