An Instance is being referred as a boolean

I am trying to setup a type of player list displaying certain stats, but I am having an issue where running the function will entirely work, but it’ll throw an error at the end of it. I have it bound to UserInputService.InputBegan, and should only run if the user hits TAB. Here is what I have, as well as the console errors.

local Services = require(game:GetService("ReplicatedStorage"):WaitForChild("Services"))
local Frame = script.Parent
local Slots = {Frame.Player1, Frame.Player2, Frame.Player3}
local Hidden = false

wait()
Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.EmotesMenu, false)
Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
for _, Slot in pairs(Slots) do Slots.Visible = false end

function InputBegan(Input)
	if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.Tab then
		if Hidden then
			Hidden = not Hidden
			Frame.Client:TweenPosition(UDim2.new(1, 0, 0, Frame.Client.Position.Y.Offset), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.3, true)
			for _, Slot in pairs(Slots) do 
				print(Slot, typeof(Slot), Slot.Position, typeof(Slot.Position))
				Slot:TweenPosition(UDim2.new(1, -10, 0, Slot.Position.Y.Offset), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.3, true) 
			end
		else
			Hidden = not Hidden
			Frame.Client:TweenPosition(UDim2.new(1.2, -60, 0, Frame.Client.Position.Y.Offset), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.3, true)
			for _, Slot in pairs(Slots) do
				print(Slot, typeof(Slot), Slot.Position, typeof(Slot.Position))
				Slot:TweenPosition(UDim2.new(1.15, 0, 0, Slot.Position.Y.Offset), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.3, true)
			end
		end
	end
end

RobloxStudioBeta_atZ0Jv7j47

“Handler” is the script that is currently running. “Slots” is simply just a table of the three frames called, “Player1”, “Player2”, “Player3”.

RobloxStudioBeta_H7gyUtSn7E

I am not exactly sure where to look to fix this as printing what my code is using shows that it’s an Instance, but the error is saying it’s a boolean…? Strangely, it does what it’s intended, and does tweenposition like it’s suppose to. It just errors after the FOR loop finishes.

Also, ignore the roblox warning. That is just self reminder of my code lol.

Can you please provide more context as to what exactly is going on? Perhaps a screenshot of the explorer (so we can see how your Slots are structured).

Yes no problem. “Handler” is the script that is currently running. “Slots” is simply just a table of the three frames called, “Player1”, “Player2”, “Player3”.

RobloxStudioBeta_H7gyUtSn7E
(This was also placed in the main thread)

The reason is because of this:

You’re adding a new entry to the Slots table, which is a boolean, and of course when you try to iterate over everything in the table, you will come across that entry and throw an error in the output.

You meant to do:

for _, Slot in pairs(Slots) do Slot.Visible = false end
1 Like

This is not the issue. Visible is simply a property of the Frame class. He is only making the frame not visible in the statement, and is not the cause of the problem.

I didn’t notice that one character error, funny enough. Strangely not sure why it still runs like normal, but fails after the FOR loop finishes.

You didn’t look at it clearly – He put slots with a “s” at the end which refers to the table, not slot without the “s” which refers to the guis

3 Likes

Is there a reason it would cause the error, even after the section runs perfectly fine? It’s suppose to tween off-screen but even when it’s overwritten with false, it will moves it off-screen.

I see. My bad. This is probably the cause of the problem.

You’re attempting to index a boolean with Position, so of course it’ll throw an error; booleans have nothing to them but evaluating statements, so you’re basically doing;

false.Position

This is the cause of error and you may think it runs perfectly fine, but it iterates over all of the guis before it gets to the boolean, because the guis are defined first with numeric indices. This is what the table would look like:

{Frame, Frame2, Frame3, ["Visible"] = false}
3 Likes

The issue you are getting is by adding an index to your slots table, called Visible. As @Rare_tendo said, it has the value false, which is a boolean. This is why the first 3 indexes print just fine, yet the Visible one does not print, as it is not an Instnace/table.

1 Like

Gotcha, I must be tired or something. I love using table to store data but somehow didn’t see this. Thanks again, both of you.