Any reason why the script doesn’t work? It’s supposed to be able to slide and save the value here are some pictures:
local script inside textlabel
local toggled = false
local debounce = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.Button.MouseButton1Click:Connect(function()
if debounce == false then
if toggled == true and game.SoundService.GameSound.Volume == 0.5 then
debounce = true
game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.25), {BackgroundColor3 = Color3.fromRGB(255, 85, 0)}):Play()
game:GetService("TweenService"):Create(script.Parent.Circle, TweenInfo.new(0.25), {Position = UDim2.new(0,2,0,2)}):Play()
game.SoundService.GameSound.Volume = 0
RE:FireServer(game.SoundService.GameSound.Volume)
wait(0.25)
debounce = false
toggled = false
elseif toggled == false and game.SoundService.GameSound.Volume == 0 then
debounce = true
game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.25), {BackgroundColor3 = Color3.fromRGB(64, 200, 114)}):Play()
game:GetService("TweenService"):Create(script.Parent.Circle, TweenInfo.new(0.25), {Position = UDim2.new(1,-20,0,2)}):Play()
game.SoundService.GameSound.Volume = 0.5
RE:FireServer(game.SoundService.GameSound.Volume)
wait(0.25)
debounce = false
toggled = true
end
end
end)
RE.OnClientEvent:Connect(function(volume)
if volume == 0.5 then
game.SoundService.GameSound.Volume = 0.5
script.Parent.BackgroundColor3 = Color3.fromRGB(64, 200, 114)
script.Parent.Circle.Position = UDim2.new(1,-20,0,2)
elseif volume == 0 then
game.SoundService.GameSound.Volume = 0
script.Parent.BackgroundColor3 = Color3.fromRGB(255, 85, 0)
script.Parent.Circle.Position = UDim2.new(0,2,0,2)
end
end)
Script in ServerScriptService
local DSService = game:GetService("DataStoreService")
local VolumeDS = DSService:GetDataStore("VolumeDS")
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("RemoteEvent")
Players.PlayerAdded:Connect(function(player)
local key = "Volume_"..player.UserId
local res = VolumeDS:GetAsync(key)
if type(res) == "number" then
RE:FireClient(player, res)
end
end)
RE.OnServerEvent:Connect(function(player, volume)
local key = "Volume_"..player.UserId
local res = VolumeDS:SetAsync(key, volume)
end)
My first guess is that the GUI isn’t loaded when the player joins the game, so there is no receiver for when the server fires the remote event to the client in your server script.
toggled is set to false when the script starts, so when the button clicks it will try to resort to this condition as toggled is not set to true. But since, GameSound is required to be 0 for it to pass, it won’t work cause GameSound is set to 0.5 by default. So instead of going to the next block, it will just end the script there.
I tried it and you have to click it two times in order for it to start displaying it turning off and on, its because toggled is set to false and its displaying as “on”.
Your solution is set GameSound’s volume back to 0.5 and set the toggled variable to true.