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)
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)
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.
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.
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)
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?