How do I make a script that detect the string Value and depend on the value, the correct part of the else is executed?

My problem is the following. I made a dataStore, very well and everything, it saves the graphics, the change of the UIS, but it does not save the scripts of the else of the scripts, I mean that I have to click 2 times for it to work, put the desired else. And I don’t know how to fix it.

2 Likes

Could you explain better what you want to achieve?
Can you also show us some scripts or the explorer?

If you are using StringValues I suggest using elseif, not else. Else is good when there are only two variables for a value, for example, true and false.

Sorry for the lateness, I couldn’t use the computer during the morning. At one point I pass a script that I want to convert.
This script is from the DataStore, it depends on the value of a stringValue, change the script (EnabledFalse, Enabled).

EnabledFalse: It is to deactivate some workspace textures, which would be another script. What the dataStore does is save the data as you wanted it and when entering again the following data would be added as you put it previously.
Enabled: It is to activate the texture of some workspace, and the script saves the configuration.

    local treeSettings = {

EnabledFalse = function(player: Player)
    		player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon:TweenPosition(UDim2.new(0.15, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0, true)
    		player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol").Abrir.BackgroundColor3 =  Color3.new(0.529412, 0.313725, 0.313725)
    		player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon.BackgroundColor3 =  Color3.new(0.509804, 0.509804, 0.509804)
    		player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon.ImageColor3 = Color3.new(1, 0.537255, 0.537255)
    		player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon.Image = "http://www.roblox.com/asset/?id=6652972833"
    	end,


Enabled = function(player: Player)
	player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon:TweenPosition(UDim2.new(0.85, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0, true)
	player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol").Abrir.BackgroundColor3 =  Color3.new(0.317647, 0.541176, 0.313725)
	player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon.BackgroundColor3 =  Color3.new(0.407843, 0.701961, 0.317647)
	player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon.ImageColor3 =  Color3.new(0.501961, 1, 0.501961)
	player:WaitForChild("PlayerGui"):WaitForChild("MenuDeMapa"):WaitForChild("Ajustes"):WaitForChild("Graficos"):WaitForChild("ScrollinGraficos"):WaitForChild("EArbol"):WaitForChild("Abrir").Icon.Image = "http://www.roblox.com/asset/?id=6652973166"
end,}

a textButton, which would be this. Comisaria - Roblox Studio 09_04_2021 08_27_08 p. m. (2)

which is what I want the else to be saved in, when you press it would change to EnabledFalse, and the else when pressing again it would be set to Enabled, but when saving and exiting, it would load the save to EnabledFalse, I must press 2 times the else to change, because if I press it once, it goes back to EnableFalse, when I want it to be Enabled.

and the following script, where I want the else to be saved, so that you do not press it 2 times to change to Enabled if it is in EnabledFalse.

local Icon = script.Parent:WaitForChild("Icon")
local Button = script.Parent
local isOpen = true 
local waitcache = 0.01
local OpenPosition = UDim2.new(0.85, 0, 0.5, 0)
local ClosePosition = UDim2.new(0.15, 0, 0.5, 0)
local tiempo = 0.3
local Debounce = true
local TweenService = game:GetService("TweenService")
local time = 1
local Tree = script.Parent.Parent.Parent.Parent:WaitForChild("Tree")

script.Parent.MouseButton1Click:Connect(function()
	if not Debounce then return end

	Debounce = false
	if isOpen then
		-- es el de apagado
		Icon:TweenPosition(ClosePosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeIn = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(1, 0.537255, 0.537255)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.509804, 0.509804, 0.509804)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.529412, 0.313725, 0.313725)})
		FadeIn:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652972833"
		Tree.Value = "EnabledFalse"
		wait(tiempo)
	else
		--encendido
		Icon:TweenPosition(OpenPosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.7, true)
		local FadeOut = TweenService:Create(Icon, TweenInfo.new(time), {ImageColor3 = Color3.new(0.501961, 1, 0.501961)})
		local FadeInOut = TweenService:Create(Icon, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.407843, 0.701961, 0.317647)})
		local FadeInColor = TweenService:Create(Button, TweenInfo.new(time), {BackgroundColor3 = Color3.new(0.317647, 0.541176, 0.313725)})
		FadeOut:Play()
		FadeInOut:Play()
		FadeInColor:Play()
		Icon.Image = "http://www.roblox.com/asset/?id=6652973166"
		Tree.Value = "Enabled"
		wait(tiempo)
	end
	wait(tiempo)
	isOpen = not isOpen 
	Debounce = true
end)

Do you have to press 2 times only the first time or all times?

When you press once for the first time it automatically changes to EnabledFalse, and when you exit and enter it will load the data mentioned above, but when you press again, the detect is changed back to enabled false, and what you have to do is press again

maybe I didn’t understand very well but try to move isOpen = not isOpen before if isOpen then

Good, no problem, I found a solution quite different solution

1 Like