Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a debounce in this case?

Well, im making a store, when you step on a Part, the shop opens and the walkspeed is set to 0. When the shop opens, one of the three sounds will play, the problem here is: The sounds don't stop playing because i am Standing on the Part that opens the shop.

The objective here is:

I stand on the part>The shop open>One of the three sounds plays. The debounce should end when the store closes but I don't know how to do it

Here the script:

local open = game.Workspace.openPart
local close = game.Workspace.closePart
local frame = script.Parent
local closeButton = frame.closeButton
local buy_1 = frame.buy1
local buy_2 = frame.buy2

local sound1 = script.Parent.Sound1
local sound2 = script.Parent.Sound2
local sound3 = script.Parent.Sound3 

local sounds = {
	sound1,
	sound2,
	sound3
}

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')

local LPlayer = game.Players.LocalPlayer  

frame.Visible = false



local function shopMenu(otherPart)
	local player = game.Players:FindFirstChild(otherPart.Parent.Name)
	local chosenSound = sounds[math.random(1, #sounds)]

	local sound = chosenSound -- define your sound

	if player == LPlayer then  

        player.PlayerGui.ScreenGui.Shop.Visible = true
		sound:Play()
		player.Character.Humanoid.WalkSpeed = 0 
	end
end



local function closeMenu()  --Updated to use LPlayer

	    LPlayer.PlayerGui.ScreenGui.Shop.Visible = false
	    script.Parent.Goodbye:Play()

	    LPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.Position.Y + 3,close.Position.Z)

		LPlayer.Character.Humanoid.WalkSpeed = 16
end

3 comments

0

You could have a debounce that you only deactivate once you've closen the menu again

0

Make sure that 'looped' is set to false on the sound.

0

I mean the other sound keep playing because im standing on the part, not because the sounds were looped

1 answer

✓ Accepted answer

you can simply check to make sure that the shop isn't already visible before opening it and playing the sound


local function shopMenu(otherPart)
    local player = game.Players:FindFirstChild(otherPart.Parent.Name)
    local chosenSound = sounds[math.random(1, #sounds)]
	local shopGui = player.PlayerGui.ScreenGui.Shop -- just so we don't have to type the same thing twice

    if player == LPlayer and not shop.Visible then  

        shop.Visible = true
        chosenSound:Play() -- you don't need two variables for the same sound
        player.Character.Humanoid.WalkSpeed = 0 
    end
end

1 comment

0

YES!!! Finally it works!! Thanks!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.