Script not Working

Hello!
So, I was making some scripts for make an Bus Inteligent Stop system, witch is based on locating a model (the bus) on workspace and calculating how much minutes or seconds are left for the bus arrives to the stop (also selected at script from workspace). So, with all that information, the scripts also takes information from bus destination system, takes the destination displayed on the bus text, and then, with all that information, the script just needs to display all that on different frames & text labels. The problem is that, when I try game on studio test or roblox game, It doesn’t shows anything, so if someone could help me, I would really appreciate it! Here is the script:

local targetBlock = workspace.BMC -- this is the bus model
local mainBlock = workspace.Model --this is the sign name on workspace (there is not any other model named like that)
local distance = (targetBlock.Position - mainBlock.Position).Magnitude
local timeInMinutes = distance / 60
local label1 = workspace.Model.SignFront.Front.Line1.Time -- here goes one time left display
local label2 = workspace.Model.SignBack.Back.Line1.Time -- here the other one time left display (there are two)
local targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num.Text -- this is the destination text displayed at the moment on the bus
if timeInMinutes <= 1 then
	label1.Text = "Inminente" -- text if time is less than a minute
	label2.Text = "Inminente" -- same too
else
	label1.Text = targetLabel.Text
	label2.Text = targetLabel.Text
end
while true do
	targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num.Text
	label1.Text = targetLabel.Text
	label2.Text = targetLabel.Text
	wait(10) -- 10 cooldown seconds before refresh if bus changed destination
end

I’m also open to any suggestion of make it from any other way, re-making some parts of the scripts for solve the issue or else, no problem with that, thanks!

4 Likes

Try placing the if statement inside the loop, as it will only run once even if the statement becomes true. Also try updating the distance and the time in minutes variables inside the forever loop.

EDIT: I’m not entirely sure exactly what this script is meant to do so I may be providing incorrect information, however I believe these suggestions could be possible solutions. There may also be other problems that I missed.

1 Like

You can’t use .Position on a model, use :GetPivot() instead

2 Likes

Hello! Thanks for the help on that. Anyways, I’ve changed that and still not working, I leave you here the modified script:

local targetBlock = workspace.BMC
local mainBlock = workspace.Model
local distance = (targetBlock:GetPivot().Position - mainBlock:GetPivot().Position).Magnitude
local timeInMinutes = distance / 60
local label1 = workspace.Model.SignFront.Front.Line1.Time
local label2 = workspace.Model.SignBack.Back.Line1.Time
local targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num.Text
if timeInMinutes <= 1 then
	label1.Text = "Inminente"
	label2.Text = "Inminente"
else
	label1.Text = targetLabel.Text
	label2.Text = targetLabel.Text
end
while true do
	targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num.Text
	label1.Text = targetLabel.Text
	label2.Text = targetLabel.Text
	wait(10)
end
2 Likes

Hello! I’ve tried making your suggestion too and still not working, I leave you here the modified script, if you can still help me out with this, It would be great, thanks!

local targetBlock = workspace.BMC
local mainBlock = workspace.Model
local label1 = workspace.Model.SignFront.Front.Line1.Time
local label2 = workspace.Model.SignBack.Back.Line1.Time
local targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num.Text

while true do
	local distance = (targetBlock:GetPivot().Position - mainBlock:GetPivot().Position).Magnitude
	local timeInMinutes = distance / 60

	if timeInMinutes <= 1 then
		label1.Text = "Inminente"
		label2.Text = "Inminente"
	else
		label1.Text = targetLabel.Text
		label2.Text = targetLabel.Text
	end

	targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num.Text
	label1.Text = targetLabel.Text
	label2.Text = targetLabel.Text

	wait(10)
end
2 Likes

found the problem, remove the .Text at the end of this line

2 Likes

I was about to say that, however it could be that the textlabels/textbuttons name is Text. But that is likely the issue.

2 Likes

That’s possible too
If the textlabels/textbuttons name is Text, use this code

local targetBlock = workspace.BMC
local mainBlock = workspace.Model
local label1 = workspace.Model.SignFront.Front.Line1.Time
local label2 = workspace.Model.SignBack.Back.Line1.Time
local targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num:FindFirstChild("Text")

while true do
	local distance = (targetBlock:GetPivot().Position - mainBlock:GetPivot().Position).Magnitude
	local timeInMinutes = distance / 60

	if timeInMinutes <= 1 then
		label1.Text = "Inminente"
		label2.Text = "Inminente"
	else
		label1.Text = targetLabel.Text
		label2.Text = targetLabel.Text
	end

	targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num:FindFirstChild("Text")
	label1.Text = targetLabel.Text
	label2.Text = targetLabel.Text

	wait(10)
end

If not, use this one

local targetBlock = workspace.BMC
local mainBlock = workspace.Model
local label1 = workspace.Model.SignFront.Front.Line1.Time
local label2 = workspace.Model.SignBack.Back.Line1.Time
local targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num

while true do
	local distance = (targetBlock:GetPivot().Position - mainBlock:GetPivot().Position).Magnitude
	local timeInMinutes = distance / 60

	if timeInMinutes <= 1 then
		label1.Text = "Inminente"
		label2.Text = "Inminente"
	else
		label1.Text = targetLabel.Text
		label2.Text = targetLabel.Text
	end

	targetLabel = workspace.BMC.Main.Body.Destination.MainSign.SurfaceGui.Num
	label1.Text = targetLabel.Text
	label2.Text = targetLabel.Text

	wait(10)
end

Btw, you should use task.wait(10) instead of wait(10) because it updates 2x faster, therefore being more accurate

1 Like

I’ve made that as you told me and still not working, that targetlabel is for take the actual destination for display at a different one.

Okay so I made that, and nothing changed, i’m sorry for this being so complicated, but if someone can still help me to reach out the exact problem, that would be great!

EDIT: I will be posting new message where I explain what exactly I want to make and there if you are still interested on helping, you will find everything.

I am still interested in helping. I have just been busy and unable to come online.

check out here my new topic of what I want to exactly make: How can i make this? - #5 by Elc2503093