Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i get a part to play a sound when another part/keycard hits it?

okay, I need help. How do i get a part to play a sound when another part/keycard hits the part that is needed to play a sound. to play the sound ive tried so many things but i don't know how to script? :( (it maybe a little tricky to read but im not English or american im from denmark so not the best you know)

1 answer

Hi there! Here's a script to put in your part that is touched by a keycard:

cooldown = 0

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Keycard" and cooldown == 0 then
		cooldown = 1
		game.workspace:FindFirstChild("Part").Sound:Play()
		wait(game.workspace:FindFirstChild("Part").Sound.TimeLength)
		cooldown = 0
	end
end)

This is assuming that the part that plays the sound is in the workspace. Make sure that the script to put in your part that is touched by the keycard is a regular script, and not a local script, otherwise it will not work. Let me know if you have any other questions! :D

4 comments

1

okay thank you do i need to set a sound player in the one thats gonna play the sound?

1

Yes, click on toolbox, go to audio, and search for a sound you'd like :) make sure it's parenting the part that plays the sound

1

Okay Thank you so much

1

No problem! Make sure to mark this as "answered", I'd really appreciate it!

This discussion is preserved as it was. New answers, comments, and votes are closed.