Settings slider

Any reason why the script doesn’t work? It’s supposed to be able to slide and save the value here are some pictures:
image
image

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)
1 Like

Do you mind sending the roblox model file for this? It’s kinda hard to find the issue by looking at your code.

Wait i will send a uncopylocked link so you can edit it, wait a few seconds

1 Like

Getting first model ever :slight_smile: now we can help you easily

1 Like

What is GameSound’s volume property set as?

oh i forgot to put that in the uncopylocked version but its a sound in soundservice
image

I just need to know what the volume property is set as

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.

1 Like

ohhh, so the issue was basically that GameSound needs to be set to 0?

Exactly. ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

Actually yes the toggled variable setted to false and sound volume is 0.5 so it doesnt detects anything.

It doesn’t seem to work even if i change the value to 0

just make the toggled variable to true and everything will be fine.
image

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.

It now switches of, but it doesn’t switch back on

just copy this

local toggled = true
local debounce = false

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
			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
			wait(0.25)
			debounce = false
			toggled = true
		end
	end
end)

GameSound needs to be 0.5

should i give you a updated version? or continue abou tthis? its your opinion :slight_smile: