Play Sounds Locally

Hi, i have a problem with playing sounds locally.
I’ve made a module script inside starterPlayerScript (and required by a local script), that just Play() some sounds inside SoundService.

The problem is that the sound will replicate even for the server if i play it locally idk why.

-- @title: AnimationsFrameHandler
-- @author: Simo 
-- @date: 5/19/24
-- @type: Client

-- <- Services -> --
local tweenService			= game:GetService("TweenService")
local collectionService		= game:GetService("CollectionService")
local soundService			= game:GetService("SoundService")
local socialService 		= game:GetService("SocialService")
local players				= game:GetService("Players")

-- <- Variables -> --
local sizes 				= {
	normalSize = UDim2.new(0.96, 0,0.159, 0),
	hoveringSize = UDim2.new(0.98, 0,0.174, 0),
	pressingSize = UDim2.new(0.9, 0,0.142, 0)
}

local favouriteSizes		= {
	normalSize = UDim2.new(0.15, 0,0.582, 0),
	hoveringSize = UDim2.new(0.22, 0,0.652, 0),
	pressingSize = UDim2.new(0.12, 0,0.552, 0)
}

local player				= players.LocalPlayer


--Sounds
local guiSounds				= soundService:WaitForChild("GuiSounds")
local clickSound			= guiSounds:WaitForChild("Click")

local AnimationSounds		= soundService:WaitForChild("AnimationSounds")


--Gui Related
local playerGui				= player.PlayerGui
local animationsFrame		= playerGui:WaitForChild("Main")["Menu's"].Animations
local textBox				= animationsFrame.TextBox
local scrollingFrame		= animationsFrame.ScrollingFrame

--Others
local char					= player.Character or player.CharacterAdded:Wait()
local humanoid				= char:WaitForChild("Humanoid")

local lastAnim				= nil
local lastSound				= nil

-- <- Init -> --
local AnimationsFrameHandler 		= {
	Name = "AnimationsFrameHandler"
};

-- <- Functions ->
local function buttonHover(frame, isHovering, sizes)
	if isHovering then
		tweenService:Create(frame, TweenInfo.new(0.8, Enum.EasingStyle.Elastic), {Size = sizes.hoveringSize}):Play()
	else
		tweenService:Create(frame, TweenInfo.new(0.4, Enum.EasingStyle.Elastic), {Size = sizes.normalSize}):Play()
	end
end

local function buttonClick (frame, clicked, sizes)
	if clicked then
		clickSound:Play()
		tweenService:Create(frame, TweenInfo.new(0.4, Enum.EasingStyle.Elastic), {Size = sizes.normalSize}):Play()
	else
		tweenService:Create(frame, TweenInfo.new(0.8, Enum.EasingStyle.Elastic), {Size = sizes.pressingSize}):Play()
	end
end

local function searchUpdate(text)
	for i, frame in pairs(scrollingFrame:GetChildren()) do
		if frame:IsA("Frame") then
			if text == "" then
				frame.Visible = true
			else
				local danceName = frame:GetAttribute("name")
				if danceName then
					local frameName = string.lower(danceName)
					local textToFind = string.lower(text)
					if not (string.find(frameName, textToFind)) then
						frame.Visible = false
					else
						frame.Visible = true
					end
				end
			end
		end
	end
end


-- <- Main -> --

for i, button in pairs(collectionService:GetTagged("AnimationsButton")) do
	local animation = button.Parent:WaitForChild("Animation"):WaitForChild("idle")
	local anim	= humanoid:LoadAnimation(animation)

	button.MouseEnter:Connect(function()
		buttonHover(button.Parent, true, sizes)
	end)
	button.MouseLeave:Connect(function()
		buttonHover(button.Parent, false, sizes)
	end)
	button.MouseButton1Down:Connect(function()
		buttonClick(button.Parent, false, sizes)
	end)
	button.MouseButton1Click:Connect(function()
		buttonClick(button.Parent, true,sizes)

		if lastAnim == anim then
			lastAnim:Stop()
			lastAnim = nil
			if lastSound then
				lastSound:Stop()
				lastSound = nil
			end

			return
		end

		if lastAnim then
			lastAnim:Stop()
		end

		anim:Play()
		lastAnim = anim

		if lastSound then
			lastSound:Stop()
		end
		local sound = AnimationSounds:FindFirstChild(button.Name)
		if sound then
			sound:Play()
			lastSound = sound
		end

	end)
end

for i, button in pairs(collectionService:GetTagged("FavouriteButton")) do
	local uiGradient = button:WaitForChild("UIGradient")
	button.MouseEnter:Connect(function()
		buttonHover(button, true, favouriteSizes)
	end)
	button.MouseLeave:Connect(function()
		buttonHover(button, false, favouriteSizes)
	end)
	button.MouseButton1Down:Connect(function()
		buttonClick(button, false, favouriteSizes)
	end)
	button.MouseButton1Click:Connect(function()
		buttonClick(button, true,favouriteSizes)
		if uiGradient.Enabled == true then
			local newName = string.sub(button.Parent.Name, 4 + 1)
			button.Parent.Name = newName
			uiGradient.Enabled = false
		else
			button.Parent.Name = "AAAA" .. button.Parent.Name
			uiGradient.Enabled = true
		end
	end)
end


textBox.Changed:Connect(function()
	searchUpdate(textBox.Text)
end)




return AnimationsFrameHandler

1 Like

Believe it or not, you can use SoundService:PlayLocalSound()

1 Like

ik but idk why it replicate in the server with just Play(), it should just play in local side , maybe some network priviledge to disable or else?

alr i found out the solution by myself

it was this option in sound service:

Screenshot 2024-05-28 225940

basically if you set it off it will just play the sounds for everyone

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.