I was working on my new signalling system for a train game but :GetTouchingParts() function that I used to detect trains on a station is not working. Any mistakes? The code is not returning any error. Running server-side. Here is the code that is not working:
function checksensor(sensor)
for i,v in pairs(sensor:GetTouchingParts()) do if v.Name == “Front” or v.Name == “Wheel” or v.Name == “Wheels” then istrue = true end end
if istrue == true then
return true;
else
return false;
end
end
Code was supposed to return true if there is a detected bogie/wheel or it will return false. The only problem is it is returning false everytime. I tried the a script like this to print which parts are detected and when i try that from the console , it worked and it detected the bogie.
for _,row in pairs(game.Workspace.FullNetwork:GetChildren()) do
for _s,screen in pairs(row:GetChildren()) do
– Check if screen contains platforms
if screen.ControlGui:FindFirstChild(“Platforms”) == nil then
print(“nope this one doesnt have platforms”)
else
– If there is platforms , load the platforms to the screen
for _ui,platform in pairs(screen.ControlGui.Platforms:GetChildren()) do
– Check for platform on sensors
if game.Workspace.Sensors:FindFirstChild(platform.Name) == nil then
– print(platform.Name …" is not present in game. Renaming required ( SIGNAL_NOT_FOUND )")
else
– If there is the platform , get the status
if checksensor(game.Workspace.Sensors:FindFirstChild(platform.Name)) == true then
platform.BackgroundColor3 = Color3.fromRGB(170,0,0)
for ___,buffer in pairs(platform:GetChildren()) do
if buffer:isA(“ImageLabel”) then
buffer.BackgroundColor3 = Color3.fromRGB(170,0,0)
end
end
print(platform.Name …" found and its full ( SIGNAL_RESULT_TRUE )")
else
print(platform.Name …" found and its NOT Full ( SIGNAL_RESULT_FALSE )")
end
end
end
end
end
end
Some paths and signals are not matching the ones in the controller room this is why it finds for the paths.
Also in the testing i see that it said that the station is empty about 6 time sometimes.
It is an system for control room. When a train touches the path at the station rail , it will detect it and and change the status for that station in signalling room. It is also for signals.