Problem with changing Value in StringValue

Hello Devs!

I’m wondering why the Value isn’t changing when I pick a class.

Here is script:

--// Services
local plrs = game:GetService("Players")
local RepStor = game:GetService("ReplicatedStorage")

--// Variables
local ClassesFolder = RepStor.Classes

local Bg = script.Parent.Background
local Classes = Bg.Classes
local Scroller1 = Classes.ScrollingFrame

local Desc = Bg.Description
local Scroller2 = Desc.ScrollingFrame
local Primary = Scroller2.Primary
local Secondary = Scroller2.Secondary
local Melee = Scroller2.Melee
local Select = Scroller2.Select

local Loadout = script.Parent.Loadout
--// Functions

for i, clasSelected in pairs(Scroller1:GetChildren()) do
	for i, class in pairs(ClassesFolder:GetChildren()) do
		if clasSelected.Name == class.Name then
			clasSelected.MouseButton1Click:Connect(function()
				Primary.Text = tostring(class.Values.Primary.Value)
				Secondary.Text = tostring(class.Values.Secondary.Value)
				Melee.Text = tostring(class.Values.Melee.Value)
				
				print(clasSelected.Name)
				
				Loadout.Value = clasSelected.Name
				
				Select.MouseButton1Click:Connect(function()
					RepStor.TakeClass:FireServer(Primary.Text, Secondary.Text, Melee.Text)
				end)
			end)
		end
	end
end

Does it print clasSelected.Name correctly, if so, what does it print?

Yes, when I click e.g. Sniper, I see “Sniper” in output so it prints it correctly.

Can you try printing Loadout.Value after Loadout.Value = clasSelected.Name, and tell me what it prints?

Here is video how it looks with print(Loadout.Value)

It’s changing properly, you’re checking the value of Loadout from StarterGui, everything in there just gets replicated to PlayerGui when the player joins the game, so the loadout value in StarterGui doesn’t change. To find the correct GUI, go to Players - [your player name] - PlayerGui - Classes, then check the value of Loadout from there. I hope I explained that well, but basically what I’m saying is, StarterGui is just a container for Guis that are supposed to be replicated to the PlayerGui folder when the player joins or their character spawns in.

2 Likes

Oh… I forgot, it works in this way. I will remember it for future. Thanks for helping!

1 Like