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

How come my script doesn't work a second time, and how come it doesn't move back 0.2 and back?

Asked by 9 years ago

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:

01button = game.Workspace.Buttons.Button1
02disc = game.Workspace.PlainDisc3.Decal
03sound = Instance.new("Sound", disc)
04radioOn = false
05 
06function 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-Vector3.new(0, 0, -0.2)
12    if radioOn and sound.SoundId == "rbxassetid://210232032" then
13    button.Position=button.Position+Vector3.new(0, 0, -0.2)
14            sound:Stop()
15            radioOn = false
16        end
17    end
18end
19 
20script.Parent.ClickDetector.MouseClick:connect(onClicked)

I hope you understand

1 answer

Log in to vote
1
Answered by
yoshi8080 445 Moderation Voter
9 years ago

I fixed it, it was very simple. The errors I put in the script

01button = script.Parent.Parent.Button1
02disc =  script.Parent.Parent.Parent.PlainDisc3.Decal
03discpart = script.Parent.Parent.Parent.PlainDisc3
04sound = Instance.new("Sound", discpart) -- you placed the audio in the decal which would be better placed in the disk
05radioOn = false
06 
07function 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()
14else -- use else to make the sound be able to turn off and on
15    if radioOn and sound.SoundId == "rbxassetid://210232032" then
View all 23 lines...
Ad

Answer this question