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

(answered) Non-working collision detection script?

Asked by 4 years ago
Edited 4 years ago

I tried to make a simple collision detection script with a car and a brick. When the car touches the brick, it should stop, but when it touches the brick with my script, it doesn't.

Here's the code that I used:

CollisionDetection = script.Parent.CollisionDetection 
BrickThatShouldStop = game.Workspace.BrickThatShouldStop
throttle = script.Parent.VehicleSeat.Throttle

CollisionDetection.Touched:connect(function(hit)
    if hit == BrickThatShouldStop then
       throttle = 0
    end
end)

CollisionDetection.TouchEnded:connect(function(hit)
    if hit == BrickThatShouldStop then
        throttle = 1
    end
end)

This is what the model looks like: https://ibb.co/ZfzG2hD

When I played the game and look at the Output, this error popped up:

CollisionDetection is not a valid member of Script

edit: I fixed my own error. I removed throttle and just said 'script.Parent.VehicleSeat.Throttle', and it seems that I put CollisionDetection in the wrong spot (thanks to Nickuhhhhhhhhhh for pointing that out).

CollisionDetection = script.Parent
BrickThatShouldStop = game.Workspace.BrickThatShouldStop
throttle = script.Parent.Parent.VehicleSeat.Throttle

CollisionDetection.Touched:connect(function(hit)
    if hit == BrickThatShouldStop then
       script.Parent.Parent.VehicleSeat.Throttle = 0
    end
end)

CollisionDetection.TouchEnded:connect(function(hit)
    if hit == BrickThatShouldStop then
       script.Parent.Parent.VehicleSeat.Throttle = 1
    end
end)
0
Your positive that you have an object named CollisionDetection inside the same place that your script is in? Nickuhhhhhhhhhhhhhhh 834 — 4y

Answer this question