Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sharing data from server to client using module script only get one value of many?

Asked by 4 years ago

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 answer

Log in to vote
0
Answered by 4 years ago

I think I understand what you're trying to say. If you want to transfer from client to module, you're going to need a remoteEvent to fire.

remote:FireServer("AddToModule", data, bla)

Now on the server side you run a function on the module transferring the data. I hope this helps you solve your problem!

0
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. XviperIink 428 — 4y
Ad

Answer this question