Deathsounds on and off

what i am tryint to achieve is make the on and off button for random death sounds

but the issue is that it plays on the server and not on the clinet while i want the button to go via client

how it works is that a random sound clones from the server and gets put in the humanoidrootpart
these sounds are located in replicatedstorage[“Death Sounds”] with the button the volume gets changed via client but when the sound gets cloned it doesnt effect it
what i tried: (also i forgot how to put this in script text) local btn = script.Parent
local rp = game.ReplicatedStorage
local TweenService = game:GetService(“TweenService”)

local function updateButtonAppearance()
if btn.onoroff.Value == false then
btn.TextSize = 17
btn.Text = “Off”
elseif btn.onoroff.Value == true then
btn.TextSize = 17
btn.Text = “On”
end
end

local function setVolumeForAllSounds(volume)
local parent = rp[“Death sounds”]
local children = parent:GetChildren()
for _, child in pairs(children) do
if child:IsA(“Sound”) then
child.Volume = volume
end
end
end

btn.MouseEnter:Connect(function()
btn.Mouseenter:Play()
local targetSize = UDim2.new(0, 63, 0, 18)
local tweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(btn, tweenInfo, {Size = targetSize})
tween:Play()
updateButtonAppearance()
end)

btn.MouseLeave:Connect(function()
local targetSize = UDim2.new(0, 60, 0, 17)
local tweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(btn, tweenInfo, {Size = targetSize})
tween:Play()
btn.TextSize = 11
btn.Text = “Death Sounds”
end)

btn.MouseButton1Click:Connect(function()
btn.Onbtn:Play()
btn.onoroff.Value = not btn.onoroff.Value
setVolumeForAllSounds(btn.onoroff.Value and 1 or 0)
updateButtonAppearance()
btn.MouseLeave:Connect(function()
btn.TextSize = 11
btn.Text = “Death Sounds”
end)
end)

this is located in the button
please help me fix this error cuz i know its possible to do this.

2 Likes