How would I make the tracks switch?
Hello, I have a problem with my train track debounce and don't know how to get round it so I came here to see if anyone could help.
So, I have two pieces of track and I have joined them together as so http://prntscr.com/817eoq
What I'm aiming to do is to be able to get then pieces of track which have a slight transparency on them(http://prntscr.com/817f1w) to move when 'Train1' travels over the red detector(http://prntscr.com/817f99). I have managed to get the track working where the transparencies and cancollides change so the train can drive but, I noticed that in game players are able to walk over these detectors and move the track. The aim was to make it so the train could do that and nothing else and I tried to figure out a way to fix this problem and couldn't.
Here is the current script which I have in the train engineF(forward) so when the part touches the detector the tracks switch :- http://prntscr.com/817gm7 I also had to add scripts to the detectors which look like so :- http://prntscr.com/817gwh
Detector script---------
local buttonPressed = false
local debounce = true
local hit = game.Workspace.Train.Chassis.EngineF
if hit.Parent.Parent.Name ~= "Train" then return
game.Workspace.Train.Chassis.EngineF.Touched:connect(function(hit)
if not buttonPressed then
buttonPressed = true
if hit.Parent then
game.Workspace.Rail1.Transparency = 1
game.Workspace.Rail1.CanCollide = false
game.Workspace.Rail2.Transparency = 0
game.Workspace.Rail2.CanCollide = true
end
wait(3)
buttonPressed = false
end
end)
EngineF script---------
local buttonPressed = false
local debounce = true
game.Workspace.Detector.Touched:connect(function(hit)
if not buttonPressed then
buttonPressed = true
if hit.Parent.Name ~= "Train" then return end
game.Workspace.Rail1.Transparency = 1
game.Workspace.Rail1.CanCollide = false
game.Workspace.Rail2.Transparency = 0
game.Workspace.Rail2.CanCollide = true
end
wait(3)
buttonPressed = false
end