I'm working on a module where the server set-up the player's data using a module script. But when I update the module script to the player itself, it only fill up one value.
Server code for cloning said module template
local PlayerDataFormat = game.ReplicatedStorage.PlayerDataFormat:Clone()
PlayerDataFormat.Name = "PlayerData"
PlayerDataFormat.Parent = Player
and code that is inside said template
local module = {}
return module
Server code for inserting player data into said template
game.ReplicatedStorage.PlayerEvents.LoadData.OnServerEvent:Connect(function(Player)
repeat wait() until Player.Character
repeat wait() until Player.leaderstats
local PlayerData = require(Player.PlayerData)
PlayerData.PlayerCash = 0
PlayerData.Damage = 1
PlayerData.CoolDown = 0.5
PlayerData.Level = 0
wait(.5)
end)
When I check what's inside said module using a server script,
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
print("Check data server")
local PlayerData = require(Player.PlayerData)
for Name, Value in pairs(PlayerData) do
print(Name, Value)
end
end)
I got everything correctly. But when i update the module script using a local script for the player,
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local Data = game.ReplicatedStorage.PlayerEvents.GetData:InvokeServer()
local PlayerData = require(Player:WaitForChild("PlayerData", 20))
for Name, Value in pairs(Data) do
PlayerData.Name = Value
end
end)
In the for loop, when using print(), i got what the server would. But when i add it into the said module, it only enters one value named when printed out: Name 1. So I was very confused about where the "Name" came from. Sorry if this is lengthy, tried to provide as much information as possible with out making it longer. If i do omit some code and you need to look at it, tell me and i add said code. Thanks

1 comment
Nah, it's the opposite, when i change the player's data module using server script, it is not reflected to the client and thus I use a remote function to get the data from the server and return the data. But when i put them into the said module, only one of many values get inserted.