Working on an active train with Velocity's, but I want the train to stop when a player touches the track. I don't want the player to go with the train, when he touches the tracks. Can someone help me fix this script, and tell me what I did wrong?
TA = script.Parent.Parent.Train.A -- Locamotive TB = script.Parent.Parent.Train.B -- Locamotive B = script.Parent.Parent.Part -- Track player = game.Players B.Velocity = Vector3.new(-30,0,0) --Train speed function onTouch() if player (onTouch)then B.CanCollide = false TA.Anchored = true TB.Anchored = true else B.CanCollide = (true) TA.Anchored = false TB.Anchored = false end end B.Touched:connect(onTouch)
Touched events have a built in parameter, being the part that touched it.
TA = script.Parent.Parent.Train.A -- Locamotive TB = script.Parent.Parent.Train.B -- Locamotive B = script.Parent.Parent.Part -- Track player = game.Players B.Velocity = Vector3.new(-30,0,0) --Train speed function onTouch(hit) -- hit is whatever touched the part. if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then -- Check if the parent of whatever hit is a player B.CanCollide = false TA.Anchored = true TB.Anchored = true else B.CanCollide = (true) TA.Anchored = false TB.Anchored = false end end B.Touched:connect(onTouch)