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)