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

Can't set Value?

Asked by
KenzaXI 166
8 years ago

I made a music frame, When you click this button it's meant to stop the music It was working fine, until an update from roblox totally screwed it up! Can anyone help me please? This is the code :

local Stoper = script.Parent
function onClick()
local Sound = game.Workspace.Sound    
Sound.Volume = 0
Sound.IsPlaying = false
Sound.IsPaused = true
Sound:Destroy()
end
Stoper.ClickDetector.MouseClick:connect(onClick)


Thanks for any help!

0
Roblox did not mess anything up. You are trying to write to properties that can only be read such as 'isPaused' and 'isPlaying'. Rather you must call functions on these to start them again. DigitalVeer 1473 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

There's an easier way to stop music. There's a method in Sounds called Stop, which essentially stops the audio.

Also, you may want to make an if statement to check if the sound actually exists, otherwise the script may return an error and break if the sound is not there.

local Stoper = script.Parent

function onClick()
    local Sound = game.Workspace:FindFirstChild("Sound")
    if Sound ~= nil then --If sound is not nil then stop and destroy it.
        Sound:Stop()
        Sound:Destroy()
    end
end

Stoper.ClickDetector.MouseClick:connect(onClick)
0
Not only is it an easier way, its the only way to stop music as you cannot write to read-only properties as OP is attempting to do. DigitalVeer 1473 — 8y
0
Yeah. Spongocardo 1991 — 8y
0
Cheers for helping, I did that before but without the conditions, Thanks! KenzaXI 166 — 8y
Ad

Answer this question