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

How can I make a script that plays a sound when the player receives points?

So lets say a player gets points on the leaderstats, they will hear a local sound play but for them only (I already have a leaderstats system).

1 answer

It's fairly simple!

In a local script, use GetPropertyChangedSignal() to connect to value changes on the stat you are looking for, and afterwards, play the sound!

-- local script, to be placed either in StarterGui or StarterPlayerScripts

local players = game:GetService("Players") -- Player service

local player = players.LocalPlayer -- The local player

local stats = player.leaderstats

-- Supposing that you want to listen to a specific stat change
local stat = stats["Points"]

-- Creating the sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://"..id -- replace id with your sound's ID
sound.Looped = false
sound.Parent = workspace

-- Fired whenever the value changes
stat:GetPropertyChangedSignal("Value"):Connect(function() 
	sound:Play() -- Simple as this!
end)

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