The client sends a message to the server after a class is selected from a UI. The server sets up default DataStore2 values and listens for updates to send info back to client. My idea was to have the RemoteFunctions's server invoke add the class to the datastore and send the class back to the client (for stats gui). The function does not fire inside of PlayerAdded. Suggestions?
--server
data.Combine("DATA","gold","sh_coins","class")
spawn(function()
glbs.Plrs.PlayerAdded:connect(function(Plr)
local goldstore = data("gold",Plr)
local shcoinstore = data("sh_coins",Plr)
local classstore = data("class",Plr)
function callRemote(remote,value)
sendDataToClient:InvokeClient(Plr,remote,value)
end
callRemote('Gold',goldstore:Get(500))
callRemote('Stronghold Coins',shcoinstore:Get(0))
callRemote('Class',classstore:Get('None'))
goldstore:OnUpdate(callRemote)
shcoinstore:OnUpdate(callRemote)
classstore:OnUpdate(callRemote)
classSelected.OnServerInvoke = function(plr,Class)
print('class remote called: '..Class)
callRemote('Class',classstore:Set(Class))
end
end)
end)
--client
local function connectClasses() --to play button
for _,v in pairs(menuclass:GetChildren()) do
wait()
if v:IsA('TextButton') then
if v.Name ~= 'Back' then
local inf = tinfo(.5,Enum.EasingStyle.Elastic)
spawn(function()
v.Button.MouseButton1Click:connect(function()
--print('clickitied')
spawn(function()
ClassSelected:InvokeServer(v.Name)
end)
local goal = {}
goal.Position = menuout
local t0 = twn(menuclass,inf,goal)
t0.Completed:wait()
gbls.Debris:AddItem(startmenu,0)
spawned = true
main.Enabled = true
cam.CameraType = Enum.CameraType.Custom
end)
end)
end
end
end
end
--update stats on data load (handled by server)
function updateStats(stat,val)
menuf[stat].Text = stat..': '..val
end
--listen for data load
StatUpdate.OnClientInvoke = updateStats

1 comment
May I add the function fires outside of the PlayerAdded event,