What do you want to achieve? I am attempting to change a label’s text after a TextButton is pressed.
What is the issue? The StringValue (VPNConnected) in ReplicatedStorage will change (code below), but the label text won’t.
What solutions have you tried so far? I have looked for solutions on the Developer Hub, but have not found anything. I have also tried changing it from a LocalScript to a regular Script to see if that would do anything.
local value = game:GetService('ReplicatedStorage').VPNConnected
local Label = script.Parent.Parent.VPNStatus
script.Parent.MouseButton1Click:Connect(function()
if value.Value == "No" then
value.Value = "Yes"
else
value.Value = "No"
end
end)
if value.Value == "Yes" then
Label.Text = "You are connected"
Label.TextColor3 = Color3.new(0, 1, 0)
else
Label.Text = "You are not connected"
Label.TextColor3 = Color3.new(1, 0, 0.0156863)
end
I apologize if my code isn’t that good, I am not fluent in Lua/Luau.
the problem here is that you aren’t checking if the value changed. the code just runs once at the start and then never checks it again. you could just change the text within the if statement within the function. this also should be a localscript
local value = game:GetService('ReplicatedStorage').VPNConnected
local Label = script.Parent.Parent.VPNStatus
script.Parent.MouseButton1Click:Connect(function()
if value.Value == "No" then
value.Value = "Yes"
Label.Text = "You are connected"
Label.TextColor3 = Color3.new(0, 1, 0)
else
value.Value = "No"
Label.Text = "You are not connected"
Label.TextColor3 = Color3.new(1, 0, 0.0156863)
end
end)
you should do what @bossay6 said
the value isn’t being switched in the example (ignore this line i just didn’t see it)
so instead of this
if value.Value == "No" then
value.Value = "Yes"
else
value.Value = "No"
end
you can do a 1 liner
-- if it's 'No' then switch to 'Yes', otherwise switch to 'No'
VPN.Value = (VPN.Value == "No") and "Yes" or "No"
local VPN = game:GetService('ReplicatedStorage').VPNConnected -- rename to avoid repitition
local Label = script.Parent.Parent.VPNStatus
local function ToggleVPN()
VPN.Value = (VPN.Value == "No") and "Yes" or "No"
if VPN.Value == "Yes" then
Label.Text = "You are connected"
Label.TextColor3 = Color3.new(0, 1, 0)
else
Label.Text = "You are not connected"
Label.TextColor3 = Color3.new(1, 0, 0.0156863)
end
end
script.Parent.MouseButton1Click:Connect(ToggleVPN)