This script works fine in my game. It controls a navigation GUI for bus routes. However, there an error that occurs during the game. The error is that Line 6 is referencing a nil value (even though when I test this via the Developer Console in game, the value is still there and not nil at all!) Then after thats happened the output goes silent and the script breaks. I have these scripts all over my game in bricks and they all break... Can anyone see why?
function onTouch(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
local human = part.Parent:findFirstChild("Humanoid")
if human then
Value = game.Workspace:FindFirstChild(player.Name.."'s Car").StringValue.Value
if Value == "TwentyTwo" then
player.PlayerGui.GUI.Dashboard.Controls.Navigation.Direction.Image = "http://www.roblox.com/asset/?id=165473861"
end
wait(4)
player.PlayerGui.GUI.Dashboard.Controls.Navigation.Direction.Image = "http://www.roblox.com/asset/?id=165477023"
end
end
end
script.Parent.Touched:connect(onTouch)

2 comments
Ahh yes! I was thinking this shouldn't happen because its activated by the driver, but failed to consider the passengers who dont have a bus (or Value) hence breaking the code. Thank you!
Sorry about that small typo I made. I guess it didn't matter though.