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