RoadNames: a free, easy-to-use road-naming system

RoadNames

Hi there, i’m SouthLondonDeveloper (main: mudblood29), and i’ve created RoadNames!

What is RoadNames?

RoadNames is a free, easy-to-install system that implements road names into your Roblox game!

How to install

  1. Purchase the model here
  2. Insert the model
  3. Ungroup the contents into each service (you can delete the contents in “RoadNames”)
    That’s it!

To add a street:

  1. Insert a part and anchor it
  2. Set the part’s “Transparency” to 1 and uncheck the “CanCollide” box
  3. Size it to fit your street
  4. Set the part’s name to whatever your street name is
  5. Move the part into “RoadNames”

Additional help

If you need any additional help or have any questions, shoot me a message on DevForum!

2 Likes

This looks like a very interesting system, but I have a few concerns. Allow me to go and pick out the ones that concern me most in your LocalScript. Here it is for anyone reading. It is unedited and copied straight from your system.

while true do
	wait(0)
	
	for i, v in pairs(workspace.RoadNames:GetChildren()) do -- Gets the parts in "RoadNames"
		
		v.Touched:Connect(function() -- Checks if the part in "RoadNames" is touched
			script.Parent.Text = v.Name -- Sets the text
		end)
		
	end
end

First off, you’re wrapping your code in a while true do wait() end loop. This is bad code practice. I invoke this post fleshing out why:

Secondly, the wait() function has been replaced by the task library. Lastly, your code unnecessarily connects an event to every single road every frame. You should instead just use event-based programming as described in the post above, connecting to the Touched events in your parts just once.

I’m sorry if this reply came off as a little aggressive. That was not my intention whatsoever. Here’s a quick rewrite of your script, following most proper programming practices. It’s been fully commented for your convenience :slight_smile:

-- Services go at the top
local Players = game:GetService("Players")

-- Variables go next
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait() -- elegantly ensures that this will only run when player is loaded
local RoadNames = workspace:WaitForChild("RoadNames")
local Label = script.Parent
local Connections = {}
local Humanoid = Character:WaitForChild("Humanoid")

-- I put connections here
for _, BasePart: BasePart --[[declare a type]] in pairs(RoadNames:GetChildren()) do -- connect events only once
	table.insert(Connections, BasePart.Touched:Connect(function(otherPart) -- adds connections to a table
		if BasePart:IsDescendantOf(Character) == Character then -- check if the touched part is a member of player character 
			Label.Text = BasePart.Name
		end
	end))
end

Humanoid.Died:Connect(function()
	for _, connection in pairs(Connections) do
		connection:Disconnect() -- clean up events on death
	end
end)

I hope this helps, and I look forward to what you contribute to Roblox in the future!

2 Likes

Thank you for your feedback!

30char

why are you checking if the part is inside the player, if they are in workspace?

I just noticed, this doesnt work at all, or am i missing something

Yeah, this had wait(0) in it, thing lagged the HECK out of my game, almost thought it was something else, change wait(0) to wait(1.5) or something.