I'm trying to figure out how to make it so if the song is already playing then it cannot be played again. And possible can be enabled and disabled (turned on and off) with the same button.
local m = game.Players.LocalPlayer:GetMouse() m.KeyDown:connect(function(k) if k:lower() == "c" then local s = Instance.new("Sound") s.SoundId = "http://www.roblox.com/asset/?id=151710009" s.Name = "Sound" s.Volume = 1 s.Looped = true s.Parent = game.Workspace.DevWork.Torso s:Play() enbaled = true else if k:lower() == "v" then local s = game.Workspace.DevWork.Torso.Sound s:Destroy() end end end)
If you add an if statement that looks for an an object in your torso named "Sound" then there won't be duplicate "Sound" Objects. Here is an example:
local m = game.Players.LocalPlayer:GetMouse() m.KeyDown:connect(function(k) if k:lower() == "c" and not game.Workspace.DevWork.Torso:FindFirstChild("Sound") then --Searches for the Object "Sound" and only makes a new one if there is not already on present local s = Instance.new("Sound") s.SoundId = "http://www.roblox.com/asset/?id=151710009" s.Name = "Sound" s.Volume = 1 s.Looped = true s.Parent = game.Workspace.DevWork.Torso s:Play() --Removed your Value "enbaled = true" else if k:lower() == "v" then local s = game.Workspace.DevWork.Torso.Sound s:Destroy() -- Removed the extra "end" statement end end)