I have a gui with two buttons for two classes you can select. When you select a class, it needs to be datastored, so I created a remotefunction and linked the class (string) to my server script. The server then updates the store and sends the class string back to the client (for a gui). Upon being called, studio errors with "tables cannot be cyclic" on the line that I fired the remote with.
Here's my code:
--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()
--print('server invoked')
local c = v.Name
ClassSelected:InvokeServer(c)
--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
--SERVER
data.Combine("DATA","gold","sh_coins","class","exp","level","awakenings")
--spawn(function()
gbls.Plrs.PlayerAdded:connect(function(Plr)
--print(Plr.Name..' added')
local goldstore = data("gold",Plr)
local shcoinstore = data("sh_coins",Plr)
local classstore = data("class",Plr)
local xpstore = data("exp",Plr)
local lvlstore = data("level",Plr)
local awakenstore = data("awakenings",Plr)
local class = classstore:Get(0) --0 is none
local awakens = awakenstore:Get(0)
local lvl = lvlstore:Get(1)
local exp = xpstore:Get(0)
local xptolvl = 50
local xpmult = lvl*1.7
local lvltoawaken = 25
local lvlmult = awakens*2.5
function callRemote(remote,value)
sendDataToClient:InvokeClient(Plr,remote,value)
end
local function updateMults()
xpmult = lvl*1.7
lvlmult = awakens*2.5
end
local function addAwakening(amt)
awakens = awakens + amt
awakenstore:Increment(amt)
end
local function addLvl(amt)
lvl = lvl + amt
lvlstore:Increment(amt)
if lvl >= lvltoawaken then
addAwakening(math.ceil(awakens/lvltoawaken))
callRemote('Awakening',awakens)
updateMults()
end
callRemote('Level',lvl)
end
local function addExp(amt)
exp = exp + amt
xpstore:Increment(amt)
if exp >= xptolvl then
addLvl(math.ceil(exp/xptolvl))
callRemote('Level',lvl)
updateMults()
end
callRemote('Exp',exp)
end
callRemote('Gold',goldstore:Get(500))
callRemote('Stronghold Coins',shcoinstore:Get(0))
callRemote('Class',class)
callRemote('Exp',exp)
callRemote('Level',lvl)
callRemote('Awakening',awakens)
goldstore:OnUpdate(callRemote)
shcoinstore:OnUpdate(callRemote)
classstore:OnUpdate(callRemote)
xpstore:OnUpdate(callRemote)
lvlstore:OnUpdate(callRemote)
awakenstore:OnUpdate(callRemote)
classSelected.OnServerInvoke = function(plr,Class)
--print('class remote called: '..Class)
callRemote('Class',classstore:Set(Class))
end
end)
--end)
Any help is very appreciated! This has stumped me for a while, and I've tried changing the DS value to a number (in case it didnt take strings?) and was not successful. The print statement printed the string that I expected (the class name), and is not nil.
