Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can't set Value?

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!

1 comment

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.

1 answer

✓ Accepted answer

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)

3 comments

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.

0

Yeah.

0

Cheers for helping, I did that before but without the conditions, Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.