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

JSONEncode Error: "tables cannot be cyclic" ?

Asked by 3 years ago
Edited 3 years ago

(the format might be a little weird cus I copyed off devfourm since the site is in read only mode)

You can write your topic however you want, but you need to answer these questions: 1. What do you want to achieve? Keep it simple and clear! One of my scripts is trying to use a BindableFuntion to get a "Profile" from another script (witch is a table). Since you cannot return a table thru a BindableFuntion, I'm trying to use JSONEncode to send it.

  1. What is the issue? Include screenshots / videos if possible! An error keeps saying tables cannot be cyclic, but no where in the table is it cyclic!

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I've looked at multiple websites to find the solution, but I can't find any :dizzy_face:

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it's easier for people to help you!

``lua

-- Script #1 (Server Script)

local TeleportService = game:GetService("TeleportService") local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local HttpService = game:GetService("HttpService") local ServerStorage = game:GetService("ServerStorage") local RunService = game:GetService("RunService")

local ProfileService = require(game.ServerStorage.Modules.ProfileService)

local repEvents = ReplicatedStorage:WaitForChild("Events") local serverEvents = ServerStorage:WaitForChild("Events") local repFunctions = ReplicatedStorage:WaitForChild("Functions") local serverFunctions = ServerStorage:WaitForChild("Functions")

local DataLoaded = repEvents:WaitForChild("DataLoaded") local GetProfile = serverFunctions:WaitForChild("GetProfile")

local player = Players.PlayerAdded:Wait()

local PlayerData = { ["Gems"] = 50; ["Bucks"] = 250; } local playerData = ProfileService.GetProfileStore("PlayerData", PlayerData)

local profile = playerData:LoadProfileAsync("Player_" .. player.UserId) -- Uses ProfilesSerivce to return a table

local function getData() return HttpService:JSONEncode(profile) end

GetProfile.OnInvoke = getData

-- Script #2 (Server Script)

local TeleportService = game:GetService("TeleportService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerStorage = game:GetService("ServerStorage")

local repEvents = ReplicatedStorage:WaitForChild("Events") local serverEvents = ServerStorage:WaitForChild("Events") local repFunctions = ReplicatedStorage:WaitForChild("Functions") local serverFunctions = ServerStorage:WaitForChild("Functions")

local GetProfile = serverFunctions:WaitForChild("GetProfile") GetProfile:Invoke()> ``

Please do not ask people to write entire scripts or design entire systems for you. If you can't answer the three questions above, you should probably pick a different category.

0
Cyclic errors occur when you do things like: "game.Parent = game" greatneil80 2647 — 3y

Answer this question