Value won't change even though it says it does in the output!

Heyo! I have been scripting something similar to a plot system by @Alvin_Blox. I have come across one problem though. I have a string value in a gui called selectedworld. Whenever a player clicks the right or left button of the gui, the selectedworld value is supposed to change to the name of the world the player chooses. Everything in the script prints so it says the value changed and the current value, but when I go check if the value has changed, it is still empty.

local player = game.Players.LocalPlayer
local worldsselect = script.Parent:WaitForChild("WorldSelect")

local frame = worldsselect:WaitForChild("Frame")
local left = frame:WaitForChild("Left")
local right = frame:WaitForChild("Right")

local selectedworld = frame:WaitForChild("SelectedWorld")

local worlds = game.Workspace.Worlds

local function getworlds()
	local availableworlds = {}
	for i, world in pairs(worlds:GetChildren()) do
		table.insert(availableworlds, world.Name)
		table.sort(availableworlds)
		print(table.concat(availableworlds, ","))
	end
	return availableworlds
end

local worldtable = getworlds()

local index = 1

selectedworld.Value = worldtable[1]
print("Got here")

left.MouseButton1Click:Connect(function()
	if worlds:FindFirstChild("World "..index - 1) then
		index -= 1
	else
		index = 4
	end
	
	selectedworld.Value = worldtable[index]
	print("Changed value")
	print("Selected world value: "..selectedworld.Value)
	print(worldtable[index])
	
end)

right.MouseButton1Click:Connect(function()
	if worlds:FindFirstChild("World "..index + 1) then
		index += 1
	else
		index = 1
	end
	
	selectedworld.Value = worldtable[index]
	print("Changed value")
	print("Selected world value: "..selectedworld.Value)
	print(worldtable[index])
	
end)

Can you please tell me what I did wrong?

If I understood correctly, you are checking the value in the explorer tab. This might be a dumb question, but are you sure that you checked the stringvalue that is a descendant of the playergui of the player, and not the one that is a descendant of startergui?

No one really responded to my topic so I decided to make a string value inside the player and it worked.

1 Like