Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make the tracks switch?

Asked by 8 years ago

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

1 answer

Log in to vote
0
Answered by 8 years ago

If you don't want players touching it or anything else, then just add in a simple check. Make the train models a unique name and just create an if statement to check for it:

if hit.Parent.Name ~= "TrainModelName" then return end

Edit

EngineF script:

local buttonPressed = false 
local debounce = true

game.Workspace.Train.Chassis.EngineF.Touched:connect(function(hit) 
    if not buttonPressed then
        buttonPressed = true
        if hit.Parent.Parent.Name ~= "Train" then return
        game.Workspace.Rail1.Transparency = 1 
        game.Workspace.Rail1.CanCollide = false 
        game.Workspace.Rail2.Transparency = 0 
        game.Workspace.Rail2.CanCollide = true
    end
    buttonPressed = false
end)

Detector:

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
    buttonPressed = false
end)
0
Should I put that in the Detector too? Xsimulations 2 — 8y
0
Yeah, put it in the scripts with the detectors to make sure that a train is hitting it and nothing else. Just make sure the names match of the train model to that line. Legoman654 100 — 8y
0
http://prntscr.com/8189u0 http://prntscr.com/818a10 I have got confused, I've mixed up that much stuff together all day, I don't know how to do it :3 Would you be able to tell me pretty specifically? Xsimulations 2 — 8y
0
Just from the looks both scripts seem kind of broken. Can you just copy and paste the whole scripts and make an edit to your post with those scripts in it? Legoman654 100 — 8y
View all comments (4 more)
0
Ok, edited it. The two scripts are in there. Xsimulations 2 — 8y
0
What should I change them to, to get it working? Xsimulations 2 — 8y
0
Edited the post above. Those should work Legoman654 100 — 8y
0
I messaged you on ROBLOX, it hasn't worked . Xsimulations 2 — 8y
Ad

Answer this question