✓ Accepted answer
There are a few steps to this problem;
First: there is a more efficient way to make a function than you appear to have tried. It also appears you may have misunderstood how functions work, or tried to use a different coding language.
game.Players.PlayerAdded:connect(function (Player)
local Mouse = Player:GetMouse()
Mouse.Button1Down:connect(function ()
end)
end)
Above is how you successfully find the mouse, and then connect the click to the code.
On to problem 2: the position of the sound.
To make it play near the player, there are 2 options: place it inside a player part, or place it inside a part near the player, depending on your desired effect.
Solution 1:
game.Players.PlayerAdded:connect(function (Player)
local Mouse = Player:GetMouse()
Mouse.Button1Down:connect(function ()
local Sound = Instance.new("Sound", game.Workspace:FindFirstChild(Player.Name):WaitForChild("Head"))
Sound.SoundId = "xxxxxxxxxxxxx"
Sound:Play()
end)
end)
Solution 2:
game.Players.PlayerAdded:connect(function (Player)
local Mouse = Player:GetMouse()
Mouse.Button1Down:connect(function ()
local Part = Instance.new("Part", game.Workspace)
Part.Anchored = true
Part.CanCollide = false
Part.Position = game.Workspace:FindFirstChild(Player.Name):WaitForChild("Head").Position + Vector3.new(x, y, z)
local Sound = Instance.new("Sound", Part)
Sound.SoundId = "xxxxxxxxxxxxx"
Sound:Play()
end)
end)
1 comment
Good effort.