Problem checking if else - code does not print

Hello, I would like to validate the roles but this is not printing on the screen, what is wrong?..

I need to check if the player is in a specific role.Name or if not, but the code doesn’t work for me, what’s wrong?


-- Player:
local Player = game.Players.LocalPlayer

-- UI Screens:
local GuiToEnable_Q1 = Player.PlayerGui:WaitForChild("Question1")
local GuiToEnable_Q2 = Player.PlayerGui:WaitForChild("Question2")
local GuiToEnable_Q3 = Player.PlayerGui:WaitForChild("Question3")
local GuiToEnable_Q4 = Player.PlayerGui:WaitForChild("Question4")
local GuiToEnable_Q5 = Player.PlayerGui:WaitForChild("Question5")
local GuiToEnable_Q6 = Player.PlayerGui:WaitForChild("Question6")
local GuiToEnable_Q7 = Player.PlayerGui:WaitForChild("Question7")
local GuiToEnable_Q8 = Player.PlayerGui:WaitForChild("Question8")

-- Leaderstats:
local leaderstats = Player:WaitForChild("leaderstats")

-- TEAMS → Ladrillos a tocar

local ladrillos_team_rojo = {
	['parts'] = {
		['red_part1'] = game.Workspace.redteam.part_1;
		['red_part2'] = game.Workspace.redteam.part_2;
		['red_part3'] = game.Workspace.redteam.part_3;
		-- You can put more here..

local ladrillos_team_azul = {
	['parts'] = {
		['blue_part1'] = game.Workspace.blueteam.part_1;
		['blue_part2'] = game.Workspace.blueteam.part_2;
		['blue_part3'] = game.Workspace.blueteam.part_3;
		-- You can put more here..
	local role = leaderstats.Roles
	if role.Value == "Player" then
		print("You are in player team.") -- This does not print on screen
		print("you has not team.") -- This does not print on screen

Is it giving you any errors? If so what do they say? And what line are they coming from?

The reason maybe and the most possible reason is that this local script is not parented to a place it can work.

This might be why, you never exactly specified the ClickDetector object for any of the parts so it’s not detecting anything

Try this instead?
1 Like

Are we not gonna talk about this…?

Off topic to the question, but for god’s sake please use a table!!!

1 Like

Thanks a lot guys for the help!
@iGottic By the way, how would you recommend using the tables for this case?

local QuestionScreens = {}
local NumberOfQuestions = 8 -- Change this when you would like!
local QuestionNamePrefix = "Question"

local PlayerGui = Player.PlayerGui

for QuestionNumber = 1, NumberOfQuestions do
	local Name = QuestionNamePrefix .. QuestionNumber -- The name of the UI
	QuestionScreens[QuestionNumber] = PlayerGui:WaitForChild(Name) -- Store the UI in the table for later use

--// To get a name, access the QuestionScreens array.
--// For example, to get the UI for question 3, you can do QuestionScreens[3]

--// You can also loop through the table.

for Number, UI in pairs(QuestionScreens) do
	print("Question Number: " .. Number)
	print("The UI is: " .. UI:GetFullName())

Hopefully this helps.

1 Like

Thanks a lot! I will need to practice this but it is very helpful! :smiley:

1 Like