Street Name GUI

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!
    I want to have it so when any player touches any part of street in game (road, sidewalk, etc. Any part of the street model), the pre-existing UI in StarterGUI’s text will change to the street name that they’re on.

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

(See #3 as I’ve already had a functioning system, but it was not efficient at all. It was what I’ve seen most people using for areas/regions)

I’ve been trying different ways of scripting this but it will not work. What I’ve been trying to do is place every roadway model into groups of each street name. i.e. “Legal Way”.
image
I have tried about 6 different ways of scripting this, from a small simple script, to a large complex script, no errors, but nothing is working.
Here is the current local script I have:

local UI = game:GetService("Players").LocalPlayer.PlayerGui.StreetUI.PopupText
local LegalWay = script.Parent.LegalWay:GetDescendants()

for index, descendant in pairs(LegalWay) do
	if descendant:IsA("Part") then
		LegalWay.Touched:Connect(function()
			UI.Text = "Legal Way"
		end)
	end
end

I have never used descendants before, as I’m still relatively new to Lua, and not sure if this is proper.

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

Yes, I’ve already had a working system, but I need to change my system around. I originally was using areas, with large transparent parts. This worked, but caused major issues in game. Vehicles that were driving through these transparent parts would lag and cause the vehicle to travel at an incredibly slow speed. This also caused issues due to using a separate UI for each street. To reduce lag, I figured it should be possible to make it where I don’t have to use large transparent parts and simply use the roads I have already in game. So if anyone is to walk/drive on the street, the UI would change the same way it did with the transparent parts.

I’m pretty stuck with this problem, and was hoping someone could shed some insight on a more efficient and working way to go about this. If you have any ideas, please let me know!
Thank you all!

for index, descendant in pairs(LegalWay:GetDescendants()) do
	if descendant:IsA("Part") then
		LegalWay.Touched:Connect(function()
			UI.Text = "Legal Way"
		end)
	end
end

You have to add :GetDescendants() to actually have access to them.

1 Like

Thanks so much for the response! I figured I was using that incorrectly,
I tried your response, and the text still isn’t changing.
image

local UI = game:GetService("Players").LocalPlayer.PlayerGui.StreetUI.PopupText
local LegalWay = script.Parent.LegalWay:GetDescendants()

for index, descendant in pairs(LegalWay:GetDescendants()) do
	if descendant:IsA("Part") then
		LegalWay.Touched:Connect(function()
			UI.Text = "Legal Way"
		end)
	end
end

Could I have done something else incorrectly?
Thanks again!

It looks like it isn’t firing because you are checking for IsA(“Part”) and then firing the Touched Function inside that loop.
Try the Touched function outside the loop so it gets fired, then checks to see if the Part is valid.

1 Like

Remove GetDescendants() from:

Try changing

To descendant:IsA("BasePart")

Finally, change LegalWay in
[quote="WhiteTuxGroom, post:3, topic:1849780 if
LegalWay.Touched:
[/quote]
To descendant
Final script:


local UI = game:GetService("Players").LocalPlayer.PlayerGui.StreetUI.PopupText
local LegalWay = script.Parent.LegalWay

for index, descendant in pairs(LegalWay:GetDescendants()) do
	if descendant:IsA("BasePart") then
		descendant.Touched:Connect(function()
			UI.Text = "Legal Way"
		end)
	end
end
1 Like

Thank you guys for the response.
Unfortunately, still nothing is changing. I tried it in a few different ways as well.

local UI = game:GetService("Players").LocalPlayer.PlayerGui.StreetUI.PopupText
local LegalWay = script.Parent.LegalWay

for index, descendant in pairs(LegalWay:GetDescendants()) do
	if descendant:IsA("BasePart") then
		descendant.Touched:Connect(function()
			UI.Text = "Legal Way"
		end)

There is nothing showing up in output so it’s difficult for me to try to pinpoint what exactly isn’t functioning. :confused:

Oh wait, I just realized something. You have a LocalScript in a model in the workspace. Local scripts don’t run in the workspace, move that script to starter player scripts

You will then also have to change

To
local LegalWay = game.Workspace:WaitForChild("LegalWay")

You’re a genius! I didn’t even think of that. I was SURE it would work, but still nothing :confused:

local UI = game:GetService("Players").LocalPlayer.PlayerGui.StreetUI.PopupText
local LegalWay = game.Workspace:WaitForChild("StreetUI").LegalWay

for index, descendant in pairs(LegalWay:GetDescendants()) do
	if descendant:IsA("BasePart") then
		descendant.Touched:Connect(function()
			UI.Text = "Legal Way"
		end)
	end
end

Weird, it should have worked, can you add a print above the line where you set the text

This line:

But how is the function firing?
It appears to take all of the Parts in the table are you creating and then check to see if each individual item is Touched.
Wouldn’t it be so much easier using this method with a single transparent Part for each street using a script with a 1 second debounce to detect whether the player.Humanoid has Touched or TouchEnded it?

1 Like

So I ended up sorta going this route.
It’s not ideal to how I wanted it, but in the end, it still reduces lag, and has everything pretty confined to one area.

For those lurking, thin transparent part over each street with the name of the part the name of the street, grouped in workspace.

Then the GUI in StarterGUI with the following localscript placed below:

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local title = script.Parent.Title
local area = game.Workspace.Area

area["Legal Way"].Touched:Connect(function()
		title.Text = "Legal Way"
end)

area["Legal Way"].TouchEnded:Connect(function()
		title.Text = ""
end)

Thanks for all the help everyone!

1 Like