Attempt to get length of a Instance Value

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!
    get rid of this error

  2. What is the issue? Include screenshots / videos if possible!

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

local API = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RemoteHandler = require(script.Parent.Parent.RemoteHandler)
local Verificator = require(script.Parent.Parent.Verificator)
local Components = require(script.Parent.Parent.Components)
local ClientFunctions = require(script.Parent.Parent.ClientFunctions)
local NotificationHandler = require(script.Parent.Parent.NotificationHandler)
local Elections = require(ReplicatedStorage.Databases.Elections)
local player = Players.LocalPlayer
local canVote = RemoteHandler.Func.new("CanVote")
local submitVote = RemoteHandler.Event.new("SubmitVote")
local ShuffleTable = function(t)
	local random = Random.new(tick() * 1000)
	random:NextNumber()
	random:NextNumber()
	random:NextNumber()
	local n = #t
	while n > 2 do
		local k = random:NextInteger(1, n)
		t[n], t[k] = t[k], t[n]
		n = n - 1
	end
	return t
end
function API.Verify(inter)
	return {
		[Enum.KeyCode.F] = "Use Voting Booth"
	}
end
local debounce = false
function API.Press(inputObject, interact, context)
	if not debounce and inputObject.UserInputState == Enum.UserInputState.End then
		debounce = true
		context:Remove()
		if not next(Elections) then
			NotificationHandler.NewNotification("There are no elections currently available.", "No Elections!", "Red")
			debounce = false
			return
		end
		do
			local actionDebounce = false
			local submitDebounce = false
			ClientFunctions.MovementEnable(false)
			local hashedRes = {}
			local res = canVote:Invoke(interact.Id)
			for i = 1, #res do
				local v = res[i]
				hashedRes[v] = true
			end
			local window = Components.Window.new("Voting System")
			window:AddComponent(Components.TextLabel.new("Choose the election you would like to vote in:"))
			for i, v in pairs(Elections) do
				do
					local thisButton = Components.Button.new(v.Name, not hashedRes[i], true)
					thisButton.MouseClick:Connect(function()
						if thisButton.Enabled and not actionDebounce then
							actionDebounce = true
							if hashedRes[i] then
								window:NewPage(2)
								if v.Question then
									window:AddComponent(Components.TextLabel.new(v.Question), 2)
								else
									window:AddComponent(Components.TextLabel.new((v.Type == "STV" or v.Type == "AV") and "Rank the candidates in order of preference, 1 (most preferred) to a maximum of " .. #v.Options .. " (least preferred):" or "Select 1 candidate from the list:"), 2)
								end
								do
									local ballotPane = Components.BallotPane.new(v.Type == "STV" or v.Type == "AV")
									local submit = Components.Button.new("SUBMIT")
									local listTable = {}
									for k, cand in pairs(v.Options) do
										table.insert(listTable, {
											k,
											cand[1],
											cand[2]
										})
									end
									ShuffleTable(listTable)
									ballotPane:SetItemList(listTable)
									local function VerifyInput()
										if v.Type == "STV" or v.Type == "AV" then
											local inputs = {}
											local gotSomething = false
											local returnTable = {}
											for _, box in pairs(ballotPane.Boxes) do
												local boxText = box.Text
												local boxNumber = tonumber(boxText)
												if boxNumber and v.Options[boxNumber] then
													if inputs[boxNumber] then
														return
													end
													inputs[boxNumber] = true
													returnTable[boxNumber] = tonumber(box.Parent.Name)
													gotSomething = true
												elseif boxText ~= "" then
													return
												end
											end
											local lastGood = true
											for i = 1, #v.Options do
												if inputs[i] then
													if not lastGood then
														return
													end
													lastGood = true
												else
													lastGood = false
												end
											end
											if gotSomething then
												return returnTable
											end
										else
											return ballotPane.Selected
										end
									end
									submit.MouseClick:Connect(function()
										if not submitDebounce then
											submitDebounce = true
											local inputResult = VerifyInput()
											if inputResult then
												submitVote:Fire(interact.Id, i, inputResult)
											else
												NotificationHandler.NewNotification("Invalid input.", "Voting Error!", "Red")
											end
											window:Close()
										end
									end)
									window:AddComponent(ballotPane, 2)
									window:AddComponent(submit, 2)
									window:SwitchPage(2)
								end
							else
								window:Close()
							end
						end
					end)
					window:AddComponent(thisButton)
				end
			end
			window.OnHide:Connect(function()
				ClientFunctions.MovementEnable(true)
				wait(0.5)
				debounce = false
			end)
			window:Show()
		end
	end
end
return API

Line 47:

for i = 1, #res do

Can you show the server script that has .OnServerInvoke for CanVote? It seems to be returning an instance.

Remote Handler:

local API = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFolder = ReplicatedStorage:WaitForChild("Remotes")
local funcTable = {}
local eventTable = {}
local function ProcessRemote(remote)
	if remote:IsA("RemoteEvent") then
		eventTable[remote.Name] = remote
	else
		funcTable[remote.Name] = remote
	end
	remote.Name = ""
end
remoteFolder.ChildAdded:Connect(ProcessRemote)
for i, v in pairs(remoteFolder:GetChildren()) do
	ProcessRemote(v)
end
local Event = {}
Event.__index = Event
function Event.new(name)
	local self = {}
	setmetatable(self, Event)
	self.Name = name
	while not eventTable[name] do
		wait()
	end
	self.Bind = eventTable[name]
	self.OnEvent = self.Bind.OnClientEvent
	return self
end
function Event:Fire(...)
	self.Bind:FireServer(...)
end
local Func = {}
Func.__index = Func
function Func.new(name, callback)
	local self = {}
	setmetatable(self, Func)
	self.Name = name
	while not funcTable[name] do
		wait()
	end
	self.Func = funcTable[name]
	if callback then
		function self.Func.OnClientInvoke(...)
			return callback(...)
		end
	end
	return self
end
function Func:Invoke(...)
	return self.Func:InvokeServer(...)
end
API.Event = Event
API.Func = Func
return API

image

I meant whats on the server, this still looks like the client. It’s how you’re handling the information returned from invoking CanVote that is causing issues.
I’m looking for the server script that contains .OnServerInvoke = function()

It’s ranned from a ModuleScript.

I’m not looking for a client-sided module, I need to see the SERVER script and what it returns through the RemoteFunction CanVote

Remotes.CanVote.OnServerInvoke = function(Player)

local PlayerVoteData = {}

PlayerVoteData = Player

return PlayerVoteData

end

You are returning the Player which is an Instance. What is PlayerVoteData supposed to be? Try checking that out and make it return a table

1 Like

PlayerVoteData This is when the player votes at the voting booth, but errors out and shows nothing, the character can’t even move upon interacting with the voting booth.

PlayerVoteData = Player upon firing OnServerInvoke via CanVote

Well the reason why it is erroring is because you are trying to get the length of Player. The server is returning PlayerVoteData which you first set as {} but then override it with Player. From what I see, you should be returning a table, which means get rid of this part