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

How do I fix this if & then statement, and please describe to me what I did wrong?

Asked by 8 years ago

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)

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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)

0
One issue, my mistake, but I would like the train to continue if the player comes back off it dluckey20 25 — 8y
Ad

Answer this question