I made a script where I click the button and it supposed to move back 0.2 of the z axis which mean the music should be on, and if I click it again it is supposed to come back to normal as in come back adding 0.2 and then the music stops. It also determines to turn on if the decal is in the id I put in. Well, the problem is that I tested it and it worked on the first time, but it didn't move back or anything, and it also didn't start the sound after the second time. This is the script:
01 | button = game.Workspace.Buttons.Button 1 |
02 | disc = game.Workspace.PlainDisc 3. Decal |
03 | sound = Instance.new( "Sound" , disc) |
04 | radioOn = false |
05 |
06 | function onClicked() |
07 | if not radioOn and disc.Texture = = "rbxassetid://238387775" then |
08 | radioOn = true |
09 | sound.SoundId = "rbxassetid://210232032" |
10 | sound:Play() |
11 | button.Position = button.Position-Vector 3. new( 0 , 0 , - 0.2 ) |
12 | if radioOn and sound.SoundId = = "rbxassetid://210232032" then |
13 | button.Position = button.Position+Vector 3. new( 0 , 0 , - 0.2 ) |
14 | sound:Stop() |
15 | radioOn = false |
16 | end |
17 | end |
18 | end |
19 |
20 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
I hope you understand
I fixed it, it was very simple. The errors I put in the script
01 | button = script.Parent.Parent.Button 1 |
02 | disc = script.Parent.Parent.Parent.PlainDisc 3. Decal |
03 | discpart = script.Parent.Parent.Parent.PlainDisc 3 |
04 | sound = Instance.new( "Sound" , discpart) -- you placed the audio in the decal which would be better placed in the disk |
05 | radioOn = false |
06 |
07 | function onClicked() |
08 | if not radioOn and disc.Texture = = "rbxassetid://238387775" then |
09 | radioOn = true |
10 | sound.SoundId = "rbxassetid://210232032" |
11 | sound:Play() |
12 | button.CFrame = button.CFrame.new( 0 ,- 0.2 , 0 ) -- Use c-frame not position |
13 | wait() |
14 | else -- use else to make the sound be able to turn off and on |
15 | if radioOn and sound.SoundId = = "rbxassetid://210232032" then |