I'm trying to make a system so that when you drive on a road, it will display the road's name on a GUI in the corner. I came up with this script, however it requires an invisible block to be on the road, with CanCollide off, and also causes lag when you drive a vehicle through it.

local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(touched)
    if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
        local Player = Players:GetPlayerFromCharacter(touched.Parent)
        if Player then
			local TouchedPlayer = Players:FindFirstChild(touched.Parent.Name)
			TouchedPlayer.PlayerGui.RoadName.Frame.TextLabel.Text = script.Parent.Name
        end
    end
end)

Is there a more efficient way of doing this?

2 comments

0

it looks fine. the only thing is you might not need to check if its a model because i dont think anything else has a humanoid in it(unless your game has a lot of parts with humanoids in htem)

0

Alright, thanks!