If Statement is not running

My If statement won’t run. In the console it says…

Players.Seeker4050.PlayerScripts.LocalScript:10: attempt to index nil with 'arent'

Here is the source code.

10. if Hit.Parent.Configuration.Class.Value == "Tree" then

Here is the entire code.

1. -- Seeker4050

2. -- Data --

3. local StarterGui = game.StarterGui -- Grabs the StarterGui

4. local Info = StarterGui.ScreenGui["Info Channel"] -- Grabs the Info Text

5. local Player = game.Players.LocalPlayer
6. local Mouse = Player:GetMouse() -- Get the Mouse

7. -- Main --

8. Mouse.Button1Down:Connect(function(Hit)
9. 	
10. 	if Hit.Parent.Configuration.Class.Value == "Tree" then -- Check if an objects Class in config is Tree
11. 		
12. 		local Tree = Hit.Parent -- Get the Tree
13. 		
14. 		Info.Text = Tree.Name .. " - " .. Tree.Configuration.Health.Value -- Set Info Text to the info in Configuration
15. 		
16. 		Info.Visible = true -- Set the Info Visible
17. 		
18. 	end
19. 	
20. end)

Looks like a typo mistake to me, are you sure that you didn’t type “arent” instead of “Parent”?

2 Likes

I’m a little confused. What are you doing with hit? Do you want to get the mouse target? That would work with mouse.Target.

2 Likes

The Mouse.Button1Down event does not have any parameters.

1 Like

That’s true the Mouse.Button1Down event does not have parameters. This helped my code a lot.

I am sure this isn’t a typo mistake. Parent is being typed the correct way.

Ok, this worked but now the Infobox doesn’t come out when it’s true.

When you set the Info.Visible = true, the Info part should be visible. When you set Info.Visible = false, the info part should be invisible.

1 Like

But this didn’t work after configuring the text. It says Info.Visible = true Don’t know what is wrong.

Is this a Server sided request or Client sided?

Both. Try a print() to check if the request is even sent.

1 Like

It displayed true. Here is the console and the Scripts Added.

 09:33:59.781  Tree Target Found.  -  Client  -  LocalScript:18
  09:33:59.781  Info Visible!  -  Client  -  LocalScript:26

Script:
1. – Seeker4050

2. -- Data --

3. local StarterGui = game.StarterGui -- Grabs the StarterGui

4. local Info = StarterGui.ScreenGui["Info Channel"] -- Grabs the Info Text

5. local Player = game.Players.LocalPlayer
6. local Mouse = Player:GetMouse() -- Get the Mouse

7. -- Main --

8. Mouse.Button1Down:Connect(function()
9. 	
10. 	if Mouse.Target.Parent.Configuration.Class.Value == "Tree" then -- Check if an objects Class in config is Tree
11. 		
12. 		print("Tree Target Found.")
13. 		
14. 		local Tree = Mouse.Target.Parent -- Get the Tree
15. 		
16. 		Info.Text = Tree.Name .. " - " .. Tree.Configuration.Health.Value -- Set Info Text to the info in Configuration
17. 		
18. 		Info.Visible = true -- Set the Info Visible
19. 		
20. 		print("Info Visible!")
21. 		
22. 	end
23. 	
24. end)

oh i see. you need to use:

local player = game.Players.LocalPlayer
local Info = player.PlayerGui.ScreenGui["Info Channel"]

StarterGui is what every new player gets at the beginning.
PlayerGui is the already cloned GUI inside the player. (so what you actually see)

1 Like

Another error…

Error: 09:41:09.642 ScreenGui is not a valid member of PlayerGui "Players.Seeker4050.PlayerGui"

Edit: In the Explorer the ScreenGui is in the PlayerGui

maybe add a WaitForChild.:
player.PlayerGui:WaitForChild("ScreenGui")["Info Channel"]

1 Like

The UI is now running! Thanks!

1 Like