Things in the StarterPack replicate to the Players' backpack. Also, you should use "rbxassetid://[some id]" now.
local function onMouseClick(Player)
if not Player.Backpack:FindFirstChild("ClickAudio") then
local ls = Instance.new("Sound")
local length = 1
ls.SoundId = "rbxassetid://337638993"
ls.Name = "ClickAudio"
ls.Volume = 0.5
ls.Pitch = 1
ls.Parent = Player.Backpack
ls:Play()
game:GetService("Debris"):AddItem(ls, length)
end
end
script.Parent.MouseClick:Connect(onMouseClick)
I would also suggest making more variables for things like the Debris service. It's just good practice.
After talking in chat this is the script we came up with:
local tool = script.Parent
local Player = game.Players.LocalPlayer
local function onMouseClick()
if not Player.Backpack:FindFirstChild("ClickAudio") then
local ls = Instance.new("Sound")
local length = 1
ls.SoundId = "rbxassetid://337638993"
ls.Name = "ClickAudio"
ls.Volume = 0.5
ls.Pitch = 1
ls.Parent = Player.Backpack
ls:Play()
game:GetService("Debris"):AddItem(ls, length)
end
end
too.Activated:Connect(onMouseClick)
4 comments
the issue is im using this with a gun and when i click once, it neither makes noise nor does it shoot ever again
Looks like you're using a ClickDetector.
what would i need to do to make this work?
Button1Down