How to make music not play If player has tool

So I have a shop if the player buys a item it plays a audio but I don’t want it too play audio if the player has the audio

local Sounds = StarterGui.Sounds
local Shop = StarterGui.Shop
local PlayerGui = game.Players.LocalPlayer.PlayerGui
local Player = game.Players.LocalPlayer
local BearTrapStuff = PlayerGui.Shop.MainFrame.ItemInfo.BearTrapInfo
debounce=true
PlayerGui.Shop.MainFrame.BearTrap.MouseButton1Click:Connect(function()
	BearTrapStuff.Buy.Visible = true
	BearTrapStuff.BearTrapImage.Visible = true
	BearTrapStuff.BearTrapInfo.Visible = true
	BearTrapStuff.BearTrapPrice.Visible = true
end)

BearTrapStuff.Buy.MouseButton1Click:Connect(function(player)
	
	if Player.leaderstats.Points.Value <500 then
		
		
	else
		if debounce == true then
			
			debounce = false
		game.StarterGui.Sounds.WiseChose:Play()
			game.ReplicatedStorage.RemotesShop.BearTrap:FireServer(Player)
			wait(3)
			debounce = true
	end
	end
end)

If I’m interpreting your post correctly:

You can use Sound.IsPlaying to check if a sound is playing.

if Sounds.WiseChose.IsPlaying then
    -- do nothing
else
    Sounds.WiseChose:Play()
end

Also, while quickly reviewing your code, you’re addressing things inside of StarterGui and inside of PlayerGui. Make sure you’re exclusively using things inside of PlayerGui.

ik ik but I mean if the player owns a tool how would I make that sound not play

Why the sudden space change between separating else & if? It just feels off

Bit more organized code:

local Sounds = StarterGui.Sounds
local Shop = StarterGui.Shop
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local BearTrapStuff = PlayerGui.Shop.MainFrame.ItemInfo.BearTrapInfo
debounce = true

PlayerGui.Shop.MainFrame.BearTrap.MouseButton1Click:Connect(function()
	BearTrapStuff.Buy.Visible = true
	BearTrapStuff.BearTrapImage.Visible = true
	BearTrapStuff.BearTrapInfo.Visible = true
	BearTrapStuff.BearTrapPrice.Visible = true
end)

BearTrapStuff.Buy.MouseButton1Click:Connect(function()
	if Player.leaderstats.Points.Value < 500 and debounce == true and Player.Backpack:FindFirstChild("BearTrap") == nil and Player.Character:FindFirstChild("BearTrap") == nil then
		debounce = false
		game.StarterGui.Sounds.WiseChose:Play()
		game.ReplicatedStorage.RemotesShop.BearTrap:FireServer(Player)
        wait(3)
        debounce = true
	end
end)
1 Like