#How do I make a part that plays sound when a car drives over it like in Ultimate Driving?
4 messages · Page 1 of 1 (latest)
-- This script and the sound object would be the children of the part that is supposed to make noise when driven over
local playing = false -- The playing boolean ensures the sound only plays one time until the sound is done
script.Parent.Touched:Connect(function(otherPart)
if otherPart.Parent.Name == "Car" and not playing then
playing = true
script.Parent.Sound:Play()
script.Parent.Sound.Ended:Wait()
playing = false -- Sets playing back to false when the sound has finished playing
end
end)
just swap out "Car" for the name of the car you want rolling over it
or if you want it to be generalized for any car, maybe compare the otherPart's parent's name to a list of all the cars in the game, and if it returns true, you can guarantee it's a car colliding with the part