Make a sound local only?

This is a script to buy an item. At the end is a sound that plays if you do not have enough currency. The script works, but is there a way to make the sound nogold play local only for the player who clicked the prompt? Meaning I only want one person to hear that sound.

Is this possible?

local prompt = script.Parent.ProximityPrompt
local sound = script.Parent.Buy
local debounce = false

prompt.Triggered:Connect(function(player)
	local backpack = player.Backpack
	local Gun = game.ServerStorage.Equipment["Greater Health Potion"]

	if not debounce then

		debounce = true

		local canGiveGun = true
		if player.leaderstats.Gems.Value >= script.Parent.Gems.Value then
			for i,v in pairs(backpack:GetChildren()) do
				if v.Name == "Unlimited" then
					canGiveGun = false
				end
			end
			if canGiveGun then
				local gunClone = Gun:Clone()
				gunClone.Parent = backpack
				sound:Play()
				player.leaderstats.Gems.Value = player.leaderstats.Gems.Value - script.Parent.Gems.Value
			end
		end

		task.wait(2)
		debounce = false
	end
end)

local debounce = false

prompt.Triggered:Connect(function(player)
	local nogold = script.Parent.nogold

	if not debounce then

		debounce = true

		if player.leaderstats.Gems.Value <= script.Parent.Gems.Value then
			nogold:Play()
		end

		task.wait(2)
		debounce = false
	end

end)
3 Likes

Is the script a localscript or a serverscript?

2 Likes

The topic says how to make a sound for local

1 Like

The script is not local. It is in a part. I was just wondering if I could call that nogold sound locally.

1 Like

Use a local script to make the script only for clients.

1 Like

i think i have an idea, make a boolean value named “Play” and make a localscript in the starterplayerscript:
change your script to;

local prompt = script.Parent.ProximityPrompt
local sound = script.Parent.Buy
local debounce = false

prompt.Triggered:Connect(function(player)
	local backpack = player.Backpack
	local Gun = game.ServerStorage.Equipment["Greater Health Potion"]

	if not debounce then

		debounce = true

		local canGiveGun = true
		if player.leaderstats.Gems.Value >= script.Parent.Gems.Value then
			for i,v in pairs(backpack:GetChildren()) do
				if v.Name == "Unlimited" then
					canGiveGun = false
				end
			end
			if canGiveGun then
				local gunClone = Gun:Clone()
				gunClone.Parent = backpack
				sound:Play()
				player.leaderstats.Gems.Value = player.leaderstats.Gems.Value - script.Parent.Gems.Value
			end
		end

		task.wait(2)
		debounce = false
	end
end)

local debounce = false

prompt.Triggered:Connect(function(player)
	local nogold = script.Parent.nogold
        local playValue = player:WaitForChild("Play")
	if not debounce then

		debounce = true

		if player.leaderstats.Gems.Value <= script.Parent.Gems.Value then

			playValue.Value = true
		end

		task.wait(2)
		debounce = false
	end

end)

The Local Script:

local rs  = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local playValue = plr:WaitForChild("Play")
local nogold = wherever it is

rs.RenderStepped:Connect(function()
      if playValue == true then
            nogold:Play()
            nogold.Stopped:Wait()
            playValue = false
      end
end)

It might not work but try it.

2 Likes

This is the only solution because you can’t put prompt.Triggered in a localScript

1 Like

And who said that? You can use that.

I’ve used prompt.Triggered in my game many times

2 Likes

in a script prompt.triggered works fine, but in a local script it does not work. Or at least I cant make it workl. But I am trying AaNoxx1414’s solution right now.

2 Likes

One question, where does the boolean value go?

1 Like

Why don’t you just use a RemoteEvent? It takes a couple minutes to set it up and you can use it to play any sound you’d like on the client, as long as it’s accessible by it.

1 Like

image

1 Like

Thats cool. But when I drop it in a local script it underlines red.

1 Like

Could you please show me a screenshot?

1 Like

Because I am learning as I go and not sure how to do that for this script.

1 Like

Just pitching in with an idea here, not tested whatsoever.

But cant you make a LocalScript in StarterCharacterScripts and also create a sound locally, inside the character inside the same script somewhere.

local shopPrompt = game.Workspace.ProximityPrompt
local localPlayer = game.Players.LocalPlayer
--Get character here also
local LOCALSOUND = CHARACTERHERE.LOCALSOUND

shopPrompt.Triggered:Connect(function(plr)
      LOCALSOUND:Play()

end)
2 Likes

This is an exact copy of how the prompt is written in the working script. In local it underlines the prompt with red.

2 Likes

You haven’t defined the prompt as a variable in that script.

2 Likes

Ahh yes thank you for that. But this local script plays the sound for everyone. If I put the sound somewhere other than the part im clicking on, will it only play for me?

2 Likes

I don’t know how to do but a lot of games have this, so yes, it’s possible.

2 Likes