I am making a keycard door from prison life 0.6, with my own code. Unfortunately adding the sound thing might have the problem, but I want it to play if the keycard touches the scanner.
Code:
01 | script.Parent.Touched:Connect( function (hit) |
02 | if hit.Parent.Name = = "Admissions Keycard" then |
03 | script.Parent.keyscanner.Union.CanCollide = false |
04 | script.Parent.keyscanner.Union.Transparency = 1 |
05 | script.Parent.Sound.Playing = true |
06 | wait( 2 ) |
07 | script.Parent.Sound.Playing = false |
08 | script.Parent.keyscanner.Union.CanCollide = true |
09 | script.Parent.keyscanner.Union.Transparency = 0 |
10 | end |
11 | end ) |
Any fixes?
Note I want the "scan" part material to neon, then 2 seconds and go back to smoothplastic.
Theres a simple fix to this. According to the API page, the property Playing
only indicates if the sound is playing or not. I would guess that you can't actually make it play by changing that variable.
Instead, try doing this:
1 | local Sound = script.Parent:WaitForChild( "Sound" ) --Making sure its loaded in |
2 |
3 | Sound:Play() --play the sound |
4 |
5 | wait( 2 ) |
6 |
7 | Sound:Stop() --stop the sound |
Hope this helped.
Well actually hit.Parent recognizes it as the 'Handle' part, but you said it was the tools name, which is actually hit.Parent.Parent.
01 | script.Parent.Touched:Connect( function (hit) |
02 | if hit.Parent.Name = = "Admissions Keycard" then |
03 | script.Parent.keyscanner.Union.CanCollide = false |
04 | script.Parent.keyscanner.Union.Transparency = 1 |
05 | script.Parent.Sound:Play() |
06 | wait( 2 ) |
07 | script.Parent.Sound:Stop() |
08 | script.Parent.keyscanner.Union.CanCollide = true |
09 | script.Parent.keyscanner.Union.Transparency = 0 |
10 | end |
11 | end ) |
Use instead .Playing > :Play() or :Stop()