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).
COMMUNITY QUESTION
How can I make a script that plays a sound when the player receives points?
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.
