Script won't add 1 to number value

Very simple problem, everything in my script works just fine except for one line that is meant to add 1 onto a number value. I have the number values name right, it outputs no errors but just doesn’t add 1, anyone tell me why?

local Menu = script.Parent
local Teams = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TC = ReplicatedStorage:WaitForChild("TeamCreated")

local Team1 = Menu:WaitForChild("Team 1")
-- Rest must be filled in

local Value1 = Team1:WaitForChild("Value")
-- Rest must be filled in

local function CreateNewTeam(player)
	print(player.Name .. " has created a team")
	
	if Team1.Visible == false then
		Team1.Visible = true
		player.Team = game.Teams:FindFirstChild("Team 1")
		print("Team 1 has been created")
		Team1:WaitForChild("Username 1").Text = player.Name
		Value1.Value = Value1.Value + 1 
			-- elseif "continues onto other teams"
	end
	
end

TC.OnServerEvent:Connect(CreateNewTeam)
2 Likes

Does it print this line?
print("Team 1 has been created")

Try this out:

local Menu = script.Parent
local Teams = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TC = ReplicatedStorage:WaitForChild("TeamCreated")
local Team1 = Menu:WaitForChild("Team 1")

local function CreateNewTeam(player)
	print(player.Name .. " has created a team")
	local Value1 = Team1:FindFirstChild("Value")

    if Value1 then
        if Team1.Visible == false then
            Team1.Visible = true
            player.Team = game.Teams:FindFirstChild("Team 1")
            print("Team 1 has been created")
            Team1:WaitForChild("Username 1").Text = player.Name
            Value1.Value += 1 
                -- elseif "continues onto other teams"
        end
    else
        warn("WHY BURH UB URRHR")
    end
end

TC.OnServerEvent:Connect(CreateNewTeam)
2 Likes

No this doesn’t work, I don’t get why it isn’t working, everything in the script works just fine, it just can’t seem to add to the number value

1 Like

Yeah everything prints out and it does everything else perfectly, just that one line

1 Like

Where is your script located? I’m guessing server, right?

If so, try this:

Value1.Value += 1 
warn(Value1.Value)
1 Like

It is a server script in the gui it is editing

Does it print out an added value on the output?

You should try to tell the script that its an int value

Like uh, typechecking?

(char too low)

Ohh yeah it is printing out the right value, adding onto it, it just won’t update the value in the explorer, huh

Like yes? Just not sure if a team value is correct

Don’t mind that, just trust the output. If the server says the value is added, just trust that it is.

So other scripts will still be able to read it as the new value?

You can test that and see for yourself.

Did, doesn’t seem like any other scripts can see the new value

Are you sure that you “check” the value on your other script before warn(Value1.Value) prints out?

Yeah, value starts on 0, still reads as 0, the script adds a 1, warn(Value1.Value) prints 1 but the other script still reads 0

Okay I ran the script in serverscriptservice instead of inside the gui, it publicly changes the value, I guess roblox studio just doesn’t like server scripts being in startergui.

Try To Run the code in local script