local UserInputService = game:GetService("UserInputService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local Sound = nil
UserInputService.InputBegan:Connect(function(InputBegan)
if InputBegan.UserInputType == Enum.UserInputType.MouseButton1 then
Sound = Instance.new("Sound")
Sound.Name = HttpService:GenerateGUID()
Sound.SoundId = "http://roblox.com/asset/?id=873129141"
Sound.Parent = Players.LocalPlayer.Character
if not Sound.IsPlaying then
Sound:Play()
end
end
end)
I’ve corrected the code below. Your issue was that you were creating a new sound every time you clicked. As a result, when you clicked again a new sound was created that wasn’t playing yet.
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local Sound = Instance.new("Sound")
Sound.Name = HttpService:GenerateGUID()
Sound.SoundId = "http://roblox.com/asset/?id=873129141"
Sound.Parent = Players.LocalPlayer.Character
UserInputService.InputBegan:Connect(function(InputBegan)
if InputBegan.UserInputType == Enum.UserInputType.MouseButton1 then
if not Sound.IsPlaying then
Sound:Play()
end
end
end)
You’ve been at this long enough to know to give more information. What debugging steps have you tried? Where does the code get to? Is input being detected, is it the mouse button, is the sound even created, or is there a sound but no audio. We don’t magically fix problems, give us details when you get stuck but you are the first step in debugging, and you need to take some steps before you consult us. You also need to mark solutions and share your answers because it is very important to a community built around answering these questions and to avoid future questions of the same nature.
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local Sound = Instance.new("Sound")
Sound.Name = HttpService:GenerateGUID()
Sound.SoundId = "http://roblox.com/asset/?id=873129141"
Sound.Parent = Players
UserInputService.InputBegan:Connect(function(InputBegan)
if InputBegan.UserInputType == Enum.UserInputType.MouseButton1 then
if not Sound.IsPlaying then
Sound:Play()
end
end
end)
local UserInputService = game:GetService("UserInputService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local playing = false
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if not playing then
playing = true
local sound = Instance.new("Sound")
sound.Name = HttpService:GenerateGUID()
sound.SoundId = "rbxassetid://873129141"
sound.Parent = Players.LocalPlayer
sound:Play()
wait(sound.TimeLength)
sound:Destroy()
playing = false
end
end
end)