Strange Scripting Issue | Please help!

(PROBLEM SOLVED BY @bhristt | Accidentally had a space in one of the TextLabels)

:wave: Hello,

I’ve come across something strange that I don’t have any solution for. I’ve looked but haven’t found anything related to it (maybe I just didn’t use the right terms in the search?).

The script itself is pretty self explanatory: whenever the StringValue (“OpenValue”)'s value changes, it should check whether the value is “PerformanceTab” or not. However, after updating it the first time, it consistently shoots out the same message (either “Correct tab” or “Different tab”), despite it being different.

I’ve made absolute sure that when I look at the value in Studio it changes.

:confused: I’m really quite stumped. Any help would be greatly appreciated!

local OpenValue = script.Parent.Parent.OpenValue

OpenValue.Changed:Connect(function()
	if OpenValue.Value == "PerformanceTab" then
		print("Correct tab")
	elseif OpenValue.Value ~= "PerformanceTab" then
		print("Different tab")
	end
end)
2 Likes

is the script you’re using this in the server or client? and are you changing the value on the client or on the server?

1 Like

The script is a LocalScript and the value is also being changed locally.

could be something else because i tried it myself and it gave the the correct outputs

Can you try this and see if it works?

local OpenValue = script.Parent.Parent.OpenValue

OpenValue.Changed:Connect(function(val)
	if val == "PerformanceTab" then
		print("Correct tab")
	elseif val ~= "PerformanceTab" then
		print("Different tab")
	end
end)

Value.Changed returns the property that changed, not the value of the property that changed

Unfortunately it did not work.

your original code should work, make sure you’re referencing the correct StringValue object

I’ve made sure it is but it still wont work - thanks for trying to help though

Are you sure? The API reference seems to show otherwise, and a quick test with the following code confirms it by printing a random value every second:

workspace.Value.Changed:Connect(function(v) print(v) end)

while true do
	workspace.Value.Value = tostring(math.random(1, 100000))
	wait(1)
end

yes i’m very sure. check this.

where do you have the local script and value parented to btw?

ahhh i see it works differently for -Values

1 Like

Well it’s actually a bit complicated, I simplified it in the code so I had less explaining of what all it meant was
image

it should be script.Parent.Parent.Parent instead of script.Parent.Parent

1 Like

Yeah I’m aware, I just simplified it thinking someone would have a direct “this doesn’t work, here’s the solution”

you’re also changing the value inside of PlayerGui not inside of StarterGui right?

Yes, the value is getting changed inside of PlayerGui

Here’s the full script just in case I missed something before

local OpenValue = script.Parent.Parent.Parent.OpenValue
local Button = script.Parent

local ToggleFrameVisible = UDim2.new(0.72, 0, 0.223, 0)
local ToggleFrameHidden = UDim2.new(1.273, 0, 0.223, 0)

local TargetTab = "Interface"

OpenValue.Changed:Connect(function(val)
	print("test1")
	if val == "Interface" then
		print("correct")
		wait(0.2)
		Button:TweenPosition(ToggleFrameVisible, Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.4)
		wait(0.4)
		Button.Position = ToggleFrameVisible
	elseif val ~= "Interface" then
		print("incorrect")
		Button:TweenPosition(ToggleFrameHidden, Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.4)
		wait(0.4)
		Button.Position = ToggleFrameHidden
	end
end)

instead of elseif try just using else, should be a simple solution.
if you need to add more things use elseif val == “String” then