Need sound play for only PLAYER not for ALL

Hello what add to line what i mark to play sound only for PLAYER localy?
Need sound when leaderboard change 1+ Stage value.

Here is code:

local Stages = workspace:WaitForChild("Stages")


for i,Stage in pairs(Stages:GetChildren()) do
	
	Stage.Touched:Connect(function(touch)
		
		local humanoid
		
		if touch.Parent:FindFirstChild("Humanoid") then
			
			humanoid = touch.Parent.Humanoid
		end
		
		if touch.Parent and touch.Parent.Parent:FindFirstChild("Humanoid") then
			
			humanoid = touch.Parent.Parent.Humanoid
		end
		
		if humanoid then
			
			local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
			
			local PlayerStage = player.leaderstats.Stage.Value
			
			if tonumber(Stage.Name) == PlayerStage + 1 then
				
				player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
				
				-- what add here to play sound here localy only player hear --

			elseif tonumber(Stage.Name) > PlayerStage + 1 then
				
				humanoid.Health = 0
			end
		end
	end)
end

you can make use of remotes to tell a client to create a sound

This may help you: RemoteEvent | Documentation - Roblox Creator Hub

:beach_umbrella: Hey there!

Please utilize a Local Script for this function. A Local Script returns a function to only the Local Client and not to the server.

use a local script and play a sound through that. It will only play on the client (player)
Edit: actually since you need to play it when they hit a new stage, make a RemoteEvent and use a local script to do a OnClientEvent and use FireClient(player) to have the player hear it. Check it out here

1 Like

no there are such things as OnClientEvent for remote events. Please research before calling someone wrong.

1 Like

you can use RemoteEvent in two ways; FireClient and FireAllClients.
FireClient’s first argument is the player object to send an event to, FireAllClients sends an event to all clients

1 Like

Guys please dont offtopic this thread.
If someone have some idea, add here code what i need to use.
Thank you.

We aren’t going off-topic. Please don’t ask for whole scripts on #help-and-feedback:scripting-support We are telling you what you can use to play the sound to only a specific player. But here is what I mean:

local REvent = --Change to the RemoveEvents location.
REvent.OnClientEvent:Connect(function()
    sound:Play()
end)

Also, this is used in a local script.

2 Likes

oh, you are quite new to coding. instead of playing a sound from the server’s side, you should use a RemoteEvent to get the player’s client that went up a stage, to play a sound. This way, only that client is affected and the rest doesn’t hear anything.

Yeah that i know RemoteEvent, but how can i add them to code?

first you create a remote event, preferrably in a place like ReplicatedStorage where both client and server can access it. Then, you create a reference to it for both the client and the server. After that, you add the sound you want to be played by the client, to the client script.
When the server script determines that you went up a level, it fires the remote event which the client then picks up, after which it can play the sound.

1 Like