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

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

Asked by 6 years ago

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)

Closed as Not Constructive by User#19524

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago

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

1
okay thank you do i need to set a sound player in the one thats gonna play the sound? boysharkdk 34 — 6y
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 SnazzySpider67 53 — 6y
1
Okay Thank you so much boysharkdk 34 — 6y
1
No problem! Make sure to mark this as "answered", I'd really appreciate it! SnazzySpider67 53 — 6y
Ad