Int-Values not changing

I’ve been having this issue for a little while now, but for whatever reason my int-values in replicated storage will not change. Everything is in the right place, and there are no errors. This is being done in a server script. Any advice?

Reset function:
image
Function being called:
image
Scores location in RS:
image

1 Like

Perhaps the script is in a strange place or the :WaitForChild() is somehow causing an issue.
Alternatively there might be another script that overrides or updates these reset scores immediately after they were reset :thinking:


I tried quickly replicating the setting and this seems to work.

image

local RS = game:GetService("ReplicatedStorage")
local scores = RS:WaitForChild("Scores")

while task.wait(3) do
	print("Random score...")
	for i, v in pairs(scores:GetChildren()) do
		v.Value = math.random(1, 10)
	end
	
	task.wait(3)
	print("Resetting scores...")
	for i, v in pairs(scores:GetChildren()) do
		v.Value = 0
	end
end
1 Like

I tried using your script and it’s still not working. I also checked the other scripts and none of them even mention the scores. I’m not sure how the :WaitForChild() is messing with it, what do you suggest I replace it with?

1 Like

Interesting o-O

You could replace those four WaitForChild lines with

	for i, v in pairs(rs.Scores:GetChildren()) do
		v.Value = 0
	end

If this doesn’t work, then perhaps try printing the values before and after you change them
( print one or all the values before you call the resetscore() , and print the value again after you’ve put it to 0 - and maybe once more a few seconds after that to see if they were suddenly changed from elsewhere )

I tried it, and it prints just fine. I have no clue why it’s still not changing. I dunno what else I should try.

1 Like

share the entire code or at least with the variables you are using. in addition, what is the path of this script? I.e. where is it (for instance, a folder inside ServerScriptService)

and you said score reset is being printed in the console?

This script is in server script service, the scores are in a folder in replicated storage. Everything is printing as it should.

Here’s the whole code:

local Lighting = game:GetService("Lighting")
local Maps = game.ReplicatedStorage.Maps:GetChildren()
local Status = game.ReplicatedStorage.Status
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local rs = game.ReplicatedStorage

local funfetti = Workspace.Lobby.ConfettiEmitter 


local playerCount = Players:GetPlayers()

local Teams = game:GetService("Teams")
local FlagService = require(script.CaptureFlagService)
print("can I kick it?")
local Workspace = game:GetService("Workspace")
local map = Workspace:WaitForChild("Map")

local redsc = rs.Scores:WaitForChild("RedScore")
local bluesc = rs.Scores:WaitForChild("BlueScore")
local greensc = rs.Scores:WaitForChild("GreenScore")
local yellowsc =  rs.Scores:WaitForChild("YellowScore")

local RedTeam = Teams:WaitForChild("Red")
local BlueTeam = Teams:WaitForChild("Blue")
local GreenTeam = Teams:WaitForChild("Green")
local YellowTeam = Teams:WaitForChild("Yellow")
local RedFlagPad = workspace.flag:WaitForChild("RedFlagPad")
local BlueFlagPad = workspace.flag:WaitForChild("BlueFlagPad")
local GreenFlagPad = workspace.flag:WaitForChild("GreenFlagPad")
local YellowFlagPad = workspace.flag:WaitForChild("YellowFlagPad")



FlagService.TeamScoreActive = true
local startre = rs.Start
local endre = rs.End
local rsg = rs.rsg

local teams = {}
for _, teamName in ipairs({"Red", "Blue", "Green", "Yellow", "Lobby"}) do
	local team = game.Teams:FindFirstChild(teamName) or Instance.new("Team")
	team.Name = teamName
	team.Parent = game.Teams
	table.insert(teams, team)
end

local mapFolder = Workspace:FindFirstChild("Map") or Instance.new("Folder")
mapFolder.Name = "Map"
mapFolder.Parent = Workspace

local lobbyTeleported = {} 

local function resetscore()
	task.wait(1)

	for i, v in pairs(rs.Scores:GetChildren()) do
		v.Value = 0
	end

end

local function flags()
	FlagService.Droppable = false
	
	FlagService.SystemEnabled = true
	FlagService.ScoreSound = game.ReplicatedStorage.SoundBin:WaitForChild("FlagCaptured")
	FlagService.SoundEnabled = true
	FlagService.DropType = "TouchReturn"
	local RedFlag = FlagService.new(RedTeam, RedFlagPad)
	local BlueFlag = FlagService.new(BlueTeam, BlueFlagPad)
	local GreenFlag = FlagService.new(GreenTeam, GreenFlagPad)
	local YellowFlag = FlagService.new(YellowTeam, YellowFlagPad)

	task.delay(15, function()
		FlagService:SyncData()
	end)
end


local function assignPlayersToLobbyTeam()
	local players = Players:GetPlayers()
	for _, player in ipairs(players) do
		player.Team = teams[#teams]
	end
	wait(1) 
end

local function resetPlayers()
		local players = Players:GetPlayers()
		for _, player in ipairs(players) do
			player:LoadCharacter() 
	end
end




local function killPlayers()
	game.ReplicatedStorage.Kill:FireAllClients()
end

local function destroyMap()
	for _, obj in ipairs(mapFolder:GetChildren()) do
		obj:Destroy()
	end
end

local function teleportPlayerToLobby(player)
	if not lobbyTeleported[player.UserId] then
		local lobbySpawn = Workspace.Lobby and Workspace.Lobby:FindFirstChild("Spawn")
		if lobbySpawn then
			player.CharacterAdded:Connect(function(character)
				local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
				if humanoidRootPart then
					humanoidRootPart.CFrame = CFrame.new(lobbySpawn.Position)
					lobbyTeleported[player.UserId] = true
				end
			end)
		end
	end
end


-- Function to reset a player's stats
local function resetPlayerStats(player)
	-- Check if the player has a leaderstats folder
	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats then
		-- Iterate through all the stats and reset them
		for _, stat in leaderstats:GetChildren() do
			if stat.name == "Kills" then
				stat.Value = 0 -- Reset numeric stats to 0

			end
		end
	end
end

-- Function to reset all players' stats
local function resetAllPlayersStats()
	for _, player in Players:GetPlayers() do
		resetPlayerStats(player)
	end
end

Players.PlayerAdded:Connect(function(player)
	teleportPlayerToLobby(player)
end)





while true do
	
	
repeat
	wait(1)
	Status.Value = "4 friends required to play!"
	until #game.Players:GetPlayers() >= 1

local intermissionTime = 10
	for i = intermissionTime, 0, -1 do
		Status.Value = "Intermission: " .. i
		assignPlayersToLobbyTeam()
		wait(.25) 
	end
	
	destroyMap()

	local ChosenMap = Maps[math.random(#Maps)]
	local ClonedMap = ChosenMap.Map:Clone()

	for _, mapObject in ipairs(ClonedMap:GetChildren()) do
		local newMapObject = mapObject:Clone()
		newMapObject.Parent = mapFolder
	end
	
	RedFlagPad:MoveTo(ChosenMap.RedFlagPad.Flag.Position)
	BlueFlagPad:MoveTo(ChosenMap.BlueFlagPad.Flag.Position)
	GreenFlagPad:MoveTo(ChosenMap.GreenFlagPad.Flag.Position)
	YellowFlagPad:MoveTo(ChosenMap.YellowFlagPad.Flag.Position)

	rs.SoundBin.MapSelected:Play()
	print("Map: " .. ClonedMap.Name) 
	Status.Value = "Map: " .. ChosenMap.Name

	flags()

	wait(4)
	
	Status.Value = "Placing The Flags..."
	
	wait(1.5)

	Status.Value = "Assembling Teams..."
	
	wait(1.5)
	
	Status.Value = "Loading Players..."

	wait(1)
	
	local players = Players:GetPlayers()
	local numTeams = 4
	local teamCounters = {0, 0, 0, 0} -- Initialize counters for each team

	for i, player in ipairs(players) do
		local teamIndex = (i % numTeams) + 1
		player.Team = teams[teamIndex]
		teamCounters[teamIndex] = teamCounters[teamIndex] + 1
	end



	wait(.1)
	


	local mapSkybox = ChosenMap:FindFirstChild("Sky")
	if mapSkybox then
		Lighting.Sky.SkyboxBk = mapSkybox.SkyboxBk
		Lighting.Sky.SkyboxDn = mapSkybox.SkyboxDn
		Lighting.Sky.SkyboxFt = mapSkybox.SkyboxFt
		Lighting.Sky.SkyboxLf = mapSkybox.SkyboxLf
		Lighting.Sky.SkyboxRt = mapSkybox.SkyboxRt
		Lighting.Sky.SkyboxUp = mapSkybox.SkyboxUp
	end
	
	resetAllPlayersStats()
	resetPlayers()
	
	wait(0.1)
	
	rsg:FireAllClients()
	
	Status.Value = "Get Ready!"

	wait(5.5)

	startre:FireAllClients()
	
	local roundDurationString = ClonedMap:FindFirstChild("RoundDuration")
	local roundDuration = roundDurationString and tonumber(roundDurationString.Value) or 20

	for i = roundDuration, 0, -1 do
		Status.Value = "Game: " .. i
		wait(1)
	end
	
	Status.Value = "Time's up!"
	
	rs.Finish:FireAllClients()
	wait(5)
	wait(.1)
	assignPlayersToLobbyTeam()
	task.wait(.1)
	resetPlayers()
	endre:FireAllClients()
	
	RedFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].RedFlagPad.Flag.Position)
	BlueFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].BlueFlagPad.Flag.Position)
	GreenFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].GreenFlagPad.Flag.Position)
	YellowFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].YellowFlagPad.Flag.Position)
	
	wait(1)
	
	Status.Value = "Results Loading..."
	game.ReplicatedStorage.Results:FireAllClients()
	funfetti.confetti1.Enabled = true
	funfetti.confetti2.Enabled = true
	funfetti.confetti3.Enabled = true
	funfetti.confetti4.Enabled = true
	funfetti.confetti5.Enabled = true
	wait(3)
	Status.Value = "Showing Results"
	task.wait(15)
	funfetti.confetti1.Enabled = false
	funfetti.confetti2.Enabled = false
	funfetti.confetti3.Enabled = false
	funfetti.confetti4.Enabled = false
	funfetti.confetti5.Enabled = false
	
	print("reseting score")
	task.wait(.5)
	resetscore()
	print("score reset")

end
1 Like

replace what you wrote for resetScores with this

local function resetscore()
    task.wait(1)

    -- Debug: Print the names of all the score objects
    print("Resetting scores...")

    for _, score in pairs(rs.Scores:GetChildren()) do
        if score:IsA("IntValue") then
            print("Resetting " .. score.Name .. " to 0")
            score.Value = 0  -- Reset each score to 0
        end
    end
end
1 Like
local Lighting = game:GetService("Lighting")
local Maps = game.ReplicatedStorage.Maps:GetChildren()
local Status = game.ReplicatedStorage.Status
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local rs = game.ReplicatedStorage

local funfetti = Workspace.Lobby.ConfettiEmitter 


local playerCount = Players:GetPlayers()

local Teams = game:GetService("Teams")
local FlagService = require(script.CaptureFlagService)
print("can I kick it?")
local Workspace = game:GetService("Workspace")
local map = Workspace:WaitForChild("Map")

local redsc = rs.Scores:WaitForChild("RedScore")
local bluesc = rs.Scores:WaitForChild("BlueScore")
local greensc = rs.Scores:WaitForChild("GreenScore")
local yellowsc =  rs.Scores:WaitForChild("YellowScore")

local RedTeam = Teams:WaitForChild("Red")
local BlueTeam = Teams:WaitForChild("Blue")
local GreenTeam = Teams:WaitForChild("Green")
local YellowTeam = Teams:WaitForChild("Yellow")
local RedFlagPad = workspace.flag:WaitForChild("RedFlagPad")
local BlueFlagPad = workspace.flag:WaitForChild("BlueFlagPad")
local GreenFlagPad = workspace.flag:WaitForChild("GreenFlagPad")
local YellowFlagPad = workspace.flag:WaitForChild("YellowFlagPad")



FlagService.TeamScoreActive = true
local startre = rs.Start
local endre = rs.End
local rsg = rs.rsg

local teams = {}
for _, teamName in ipairs({"Red", "Blue", "Green", "Yellow", "Lobby"}) do
	local team = game.Teams:FindFirstChild(teamName) or Instance.new("Team")
	team.Name = teamName
	team.Parent = game.Teams
	table.insert(teams, team)
end

local mapFolder = Workspace:FindFirstChild("Map") or Instance.new("Folder")
mapFolder.Name = "Map"
mapFolder.Parent = Workspace

local lobbyTeleported = {} 

local function resetscore()
    task.wait(1)

    -- Debug: Print the names of all the score objects
    print("Resetting scores...")

    for _, score in pairs(rs.Scores:GetChildren()) do
        if score:IsA("IntValue") then
            print("Resetting " .. score.Name .. " to 0")
            score.Value = 0  -- Reset each score to 0
        end
    end
end

local function flags()
	FlagService.Droppable = false
	
	FlagService.SystemEnabled = true
	FlagService.ScoreSound = game.ReplicatedStorage.SoundBin:WaitForChild("FlagCaptured")
	FlagService.SoundEnabled = true
	FlagService.DropType = "TouchReturn"
	local RedFlag = FlagService.new(RedTeam, RedFlagPad)
	local BlueFlag = FlagService.new(BlueTeam, BlueFlagPad)
	local GreenFlag = FlagService.new(GreenTeam, GreenFlagPad)
	local YellowFlag = FlagService.new(YellowTeam, YellowFlagPad)

	task.delay(15, function()
		FlagService:SyncData()
	end)
end


local function assignPlayersToLobbyTeam()
	local players = Players:GetPlayers()
	for _, player in ipairs(players) do
		player.Team = teams[#teams]
	end
	wait(1) 
end

local function resetPlayers()
		local players = Players:GetPlayers()
		for _, player in ipairs(players) do
			player:LoadCharacter() 
	end
end




local function killPlayers()
	game.ReplicatedStorage.Kill:FireAllClients()
end

local function destroyMap()
	for _, obj in ipairs(mapFolder:GetChildren()) do
		obj:Destroy()
	end
end

local function teleportPlayerToLobby(player)
	if not lobbyTeleported[player.UserId] then
		local lobbySpawn = Workspace.Lobby and Workspace.Lobby:FindFirstChild("Spawn")
		if lobbySpawn then
			player.CharacterAdded:Connect(function(character)
				local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
				if humanoidRootPart then
					humanoidRootPart.CFrame = CFrame.new(lobbySpawn.Position)
					lobbyTeleported[player.UserId] = true
				end
			end)
		end
	end
end


-- Function to reset a player's stats
local function resetPlayerStats(player)
	-- Check if the player has a leaderstats folder
	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats then
		-- Iterate through all the stats and reset them
		for _, stat in leaderstats:GetChildren() do
			if stat.name == "Kills" then
				stat.Value = 0 -- Reset numeric stats to 0

			end
		end
	end
end

-- Function to reset all players' stats
local function resetAllPlayersStats()
	for _, player in Players:GetPlayers() do
		resetPlayerStats(player)
	end
end

Players.PlayerAdded:Connect(function(player)
	teleportPlayerToLobby(player)
end)





task.spawn(function() 
while true do
	
	
repeat
	wait(1)
	Status.Value = "4 friends required to play!"
	until #game.Players:GetPlayers() >= 1

local intermissionTime = 10
	for i = intermissionTime, 0, -1 do
		Status.Value = "Intermission: " .. i
		assignPlayersToLobbyTeam()
		wait(.25) 
	end
	
	destroyMap()

	local ChosenMap = Maps[math.random(#Maps)]
	local ClonedMap = ChosenMap.Map:Clone()

	for _, mapObject in ipairs(ClonedMap:GetChildren()) do
		local newMapObject = mapObject:Clone()
		newMapObject.Parent = mapFolder
	end
	
	RedFlagPad:MoveTo(ChosenMap.RedFlagPad.Flag.Position)
	BlueFlagPad:MoveTo(ChosenMap.BlueFlagPad.Flag.Position)
	GreenFlagPad:MoveTo(ChosenMap.GreenFlagPad.Flag.Position)
	YellowFlagPad:MoveTo(ChosenMap.YellowFlagPad.Flag.Position)

	rs.SoundBin.MapSelected:Play()
	print("Map: " .. ClonedMap.Name) 
	Status.Value = "Map: " .. ChosenMap.Name

	flags()

	wait(4)
	
	Status.Value = "Placing The Flags..."
	
	wait(1.5)

	Status.Value = "Assembling Teams..."
	
	wait(1.5)
	
	Status.Value = "Loading Players..."

	wait(1)
	
	local players = Players:GetPlayers()
	local numTeams = 4
	local teamCounters = {0, 0, 0, 0} -- Initialize counters for each team

	for i, player in ipairs(players) do
		local teamIndex = (i % numTeams) + 1
		player.Team = teams[teamIndex]
		teamCounters[teamIndex] = teamCounters[teamIndex] + 1
	end



	wait(.1)
	


	local mapSkybox = ChosenMap:FindFirstChild("Sky")
	if mapSkybox then
		Lighting.Sky.SkyboxBk = mapSkybox.SkyboxBk
		Lighting.Sky.SkyboxDn = mapSkybox.SkyboxDn
		Lighting.Sky.SkyboxFt = mapSkybox.SkyboxFt
		Lighting.Sky.SkyboxLf = mapSkybox.SkyboxLf
		Lighting.Sky.SkyboxRt = mapSkybox.SkyboxRt
		Lighting.Sky.SkyboxUp = mapSkybox.SkyboxUp
	end
	
	resetAllPlayersStats()
	resetPlayers()
	
	wait(0.1)
	
	rsg:FireAllClients()
	
	Status.Value = "Get Ready!"

	wait(5.5)

	startre:FireAllClients()
	
	local roundDurationString = ClonedMap:FindFirstChild("RoundDuration")
	local roundDuration = roundDurationString and tonumber(roundDurationString.Value) or 20

	for i = roundDuration, 0, -1 do
		Status.Value = "Game: " .. i
		wait(1)
	end
	
	Status.Value = "Time's up!"
	
	rs.Finish:FireAllClients()
	wait(5)
	wait(.1)
	assignPlayersToLobbyTeam()
	task.wait(.1)
	resetPlayers()
	endre:FireAllClients()
	
	RedFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].RedFlagPad.Flag.Position)
	BlueFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].BlueFlagPad.Flag.Position)
	GreenFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].GreenFlagPad.Flag.Position)
	YellowFlagPad:MoveTo(game.ReplicatedStorage["Lobby Flag"].YellowFlagPad.Flag.Position)
	
	wait(1)
	
	Status.Value = "Results Loading..."
	game.ReplicatedStorage.Results:FireAllClients()
	funfetti.confetti1.Enabled = true
	funfetti.confetti2.Enabled = true
	funfetti.confetti3.Enabled = true
	funfetti.confetti4.Enabled = true
	funfetti.confetti5.Enabled = true
	wait(3)
	Status.Value = "Showing Results"
	task.wait(15)
	funfetti.confetti1.Enabled = false
	funfetti.confetti2.Enabled = false
	funfetti.confetti3.Enabled = false
	funfetti.confetti4.Enabled = false
	funfetti.confetti5.Enabled = false
	
	print("reseting score")
	task.wait(.5)
	resetscore()
	print("score reset")

end
end)
1 Like

try this, didnt really take the closest look at your code but this may help

Oh, ahah. With the prints I meant this:

Which should give you numbers only. Maybe that gives some insights?

I only see the scores reset in the script. How do they go up - and is it ever possible that the script that increases them keeps running or overriding them?

Again, as for those prints, maybe in @dev_Typ’s code it could be:

print("Resetting " .. score.Name .. "'s Value from "..score.Value.." to 0")

And then perhaps a temporary loop x seconds later to again print these values and see if something strange happened :man_shrugging:

1 Like

The same issue is happening, I even tried printing all the score names and that worked properly and the number still won’t change.

1 Like

It goes up whenever a team captures a flag, this is handled in another script. It only fires that part when a flag is captured though, so I have no clue why it could be firing now. As for printing the values, it prints the number I set it to in the properties menu.

Share that code the issue might be in there somewhere

This a module script:

-- CaptureFlagService [v2]
-- Scripted by SkySpell
---------------------------------------------------------------------------------------------------------------------------------------------------------------

-- Variables
local Rep = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local System = {
	--------------------------------------------------
	SystemEnabled = true,
	TeamScoreActive = true,
	FlagType = "Accessory",
	ScoreName = "Score",
	PadBehaviorType = "Touch", -- Types: Touch (requires touch) and Radial (requires to be in a certain range)
	PadRadial = 10,
	--------------------------------------------------
	ShowPlayerLocation = true,
	LocationImage = 4506490665,
	ChangeLocationImageColor = true,
	LocationImageSize = UDim2.new(1, 0, 1, 0),
	--------------------------------------------------
	SoundEnabled = false,
	ScoreSound = nil,
	--------------------------------------------------
	Droppable = true,
	DropType = "Stay", -- Types: Stay (waits until the ReturnTime reaches 0), TeamGrab (can be grabbed by teammates), TouchReturn (returns when touched)
	DropParent = workspace,	
	DropOffset = Vector3.new(0, 1, 0),
	ReturnTime = 20,
	--------------------------------------------------
	SpectateColors = { ["medium stone grey"] = true },
	ScoreBin = nil
	--------------------------------------------------
}
local Flags = {}

if System.TeamScoreActive then
	System.ScoreBin = Rep:FindFirstChild("Scores") or Instance.new("Folder", Rep)
	System.ScoreBin.Name = "Scores"
end

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-- External Functions / Methods
---------------------------------------------------------------------------------------------------------------------------------------------------------------

local function SearchForFlag(model)
	local ValidNames = { flaghandle = true, flag = true, handle = true, }
	if model then
		for _, obj in pairs(model:GetDescendants()) do
			if ValidNames[obj.Name:lower()] and obj:IsA("BasePart") then
				return obj
			end
		end
	end
	return nil
end

local function SearchForPad(model)
	local ValidNames = { flagpad = true, pad = true, mainpad = true, }
	if model then
		for _, obj in pairs(model:GetDescendants()) do
			if ValidNames[obj.Name:lower()] and obj:IsA("BasePart") then
				return obj
			end
		end
	end
	return nil
end

local function FabricateIgnoreList()
	local Ignore = {}
	for _, obj in pairs(System.DropParent:GetChildren()) do
		if obj:IsA("BasePart") and obj.Name:lower() == "droppedflag" then
			table.insert(Ignore, 1, obj)
		end
	end
	for _, pl in pairs(Players:GetPlayers()) do
		local pChar = pl.Character
		if pChar then
			table.insert(Ignore, 1, pChar)
		end
	end
	return Ignore
end

local function DetectFloor(rootpos)
	if rootpos then
		local NewRay = Ray.new(rootpos, Vector3.new(0, -100, 0))
		local Part, Position = workspace:FindPartOnRayWithIgnoreList(NewRay, FabricateIgnoreList())
		return (Part ~= nil)
	end
	return false
end

local function OnFlagHit(flagInfo, hit)
	if flagInfo and hit and (not flagInfo.Captured or flagInfo.Dropped) and hit.Parent ~= flagInfo.FlagModel and System.SystemEnabled then
		local HitHum = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
		local HitPlayer = HitHum and Players:GetPlayerFromCharacter(HitHum.Parent)
		local HitFlag = HitHum and HitHum.Parent:FindFirstChild("FlagHat")
		local HumanoidRoot = HitHum and HitHum.Parent:FindFirstChild("HumanoidRootPart")
		if HitHum and HitHum.Health > 0 and HitPlayer and not HitPlayer.Neutral and not System.SpectateColors[HitPlayer.TeamColor.Name:lower()] and HitFlag == nil then
			return HitHum.Parent, HitHum, HumanoidRoot -- this means that the capture is valid.
		end
	end
	return nil, nil, nil
end

local function OnPadHit(flagInfo, hit)
	if flagInfo and hit and hit.Parent ~= flagInfo.FlagModel and System.SystemEnabled then
		local HitHum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
		local HitPlayer = HitHum and Players:GetPlayerFromCharacter(HitHum.Parent)
		if HitHum and HitHum.Health > 0 and HitPlayer and HitPlayer.TeamColor == flagInfo.Team.TeamColor and not System.SpectateColors[HitPlayer.TeamColor.Name:lower()] then
			return HitHum.Parent, HitPlayer -- this means that the capture is valid.
		end
	end
	return nil, nil
end

local function GiveUserFlagObject(handle, team, parent)
	if handle and handle:IsA("BasePart") and parent and team then
		local FinalParent = nil
		if System.FlagType:lower() == "accessory" then
			FinalParent = Instance.new("Accessory")
			FinalParent.Name = "FlagHat"
		elseif System.FlagType:lower() == "tool" then
			FinalParent = Instance.new("Tool")
			FinalParent.Name = team.Name:gsub("%s+", "").."Flag"
			FinalParent.CanBeDropped = false
			FinalParent.GripPos = Vector3.new(1, 0, 0)
			FinalParent.GripRight = Vector3.new(0, 0, -1)
			FinalParent.GripUp = Vector3.new(0, 1, 0)
			FinalParent.GripForward = Vector3.new(-1, 0, -0)
		end
		if FinalParent then
			local NewHandle = handle:Clone()
			NewHandle.Name = "Handle"
			NewHandle.Transparency = 0
			if System.FlagType:lower() == "accessory" and not NewHandle:FindFirstChildOfClass("Attachment") then
				local Attachment = Instance.new("Attachment", NewHandle)
				Attachment.Name = "BodyBackAttachment"
				Attachment.Orientation = Vector3.new(0, 0, -15)
				Attachment.Position = Vector3.new(0.5, 0, -0.22)
			end
			NewHandle.Parent = FinalParent
			NewHandle.Anchored = false
			local TeamOwner = Instance.new("ObjectValue", FinalParent)
			TeamOwner.Name = "TeamOwner"
			TeamOwner.Value = team
			FinalParent.Parent = workspace
			return FinalParent
		end
	end
	return nil
end

local function ClearFlagObjects(character, backpack)
	if character then
		for _, obj in pairs(character:GetChildren()) do
			if obj.Name:lower() == "flaghat" then
				obj:Destroy()
			end
		end
	end
	if backpack then
		for _, obj in pairs(backpack:GetChildren()) do
			if obj:FindFirstChild("TeamOwner") then
				obj:Destroy()
			end
		end
	end
end

local function FindFlagObject(character, backpack)
	if character then
		for _, obj in pairs(character:GetChildren()) do
			if obj.Name:lower() == "flaghat" then
				return obj
			end
		end
	end
	if backpack then
		for _, obj in pairs(backpack:GetChildren()) do
			if obj:FindFirstChild("TeamOwner") then
				return obj
			end
		end
	end
end

local function FindTeamInfo(teamObject)
	if teamObject and teamObject:IsA("ObjectValue") and teamObject.Value then
		local Logic, _ = System:FindTeam(teamObject.Value)
		return Logic
	end
end

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Module Functions / Methods
---------------------------------------------------------------------------------------------------------------------------------------------------------------

function System.new(teamObject, flagModel)
	-------------------------------------------------------------------------------------------------------------
	if teamObject == nil or not teamObject:IsA("Team") then 
		warn("TeamObject is not a valid parameter.") 
		return nil
	else
		local Logic, _ = System:FindTeam(teamObject)
		if Logic then return Logic end
	end

	-------------------------------------------------------------------------------------------------------------

	-------------------------------------------------------------------------------------------------------------
	-- Internal Variables
	-------------------------------------------------------------------------------------------------------------

	-- Table Variables
	local Logic = {}
	local Connections = {} -- value: { ConnectionName = "Test", RawConnection = whatever_lol }
	local Internal = {}
	local billboard =  nil

	-- Logic Properties
	---------------------------------------------------------------------------------
	Logic.Team = teamObject
	---------------------------------------------------------------------------------
	Logic.FlagModel = nil
	Logic.FlagOwner = nil
	Logic.FlagHandle = nil
	Logic.FlagPad = nil
	---------------------------------------------------------------------------------
	Logic.Enabled = false
	Logic.Captured = false
	Logic.Dropped = false
	---------------------------------------------------------------------------------
	Logic.FlagType = System.FlagType
	Logic.PadBehaviorType = System.PadBehaviorType
	Logic.PadRadial = System.PadRadial
	---------------------------------------------------------------------------------
	Logic.ReturnTime = System.ReturnTime
	Logic.Droppable = System.Droppable
	Logic.DropType = System.DropType
	Logic.ShowPlayerLocation = System.ShowPlayerLocation
	Logic.ScoreSound = System.ScoreSound
	Logic.DropOffset = System.DropOffset
	---------------------------------------------------------------------------------
	Logic.LocationImage = System.LocationImage
	Logic.ChangeLocationImageColor = System.ChangeLocationImageColor
	Logic.LocationImageSize = System.LocationImageSize
	---------------------------------------------------------------------------------
	Logic.Score = nil
	if System.TeamScoreActive then
		local scoreName = teamObject.Name:gsub("%s+", "").."Score"
		local existingScore = System.ScoreBin:FindFirstChild(scoreName)
		if not existingScore then
			Logic.Score = Instance.new("StringValue", System.ScoreBin)
			Logic.Score.Name = scoreName
			Logic.Score.Value = "0"
		else
			Logic.Score = existingScore
		end
	end

	---------------------------------------------------------------------------------

	-------------------------------------------------------------------------------------------------------------
	-- Internal Functions / Methods
	-------------------------------------------------------------------------------------------------------------

	function Internal:SearchForConnection(name)
		if name then
			for i = 1, #Connections do
				local ConData = Connections[i]
				if ConData and ConData.ConnectionName and ConData.ConnectionName:lower() == tostring(name):lower() then
					return i, ConData
				end
			end
		end
		return nil, nil
	end

	function Internal:Disconnect(name)
		if name then
			local Number, Data = Internal:SearchForConnection(name)
			if Number and Data then
				if Data.RawConnection then
					Data.RawConnection:disconnect()
					Data.RawConnection = nil
				end
				table.remove(Connections, Number)
			end
		end
	end

	function Internal:EstablishConnection(name, connection)
		if name and connection then
			table.insert(Connections, 1, { ConnectionName = tostring(name), RawConnection = connection })
		end
	end

	local function ApplyLocation(object, owner, tcolor)
		if object and owner and tcolor and Logic.ShowPlayerLocation then
			local Billboard = Instance.new("BillboardGui", object)
			Billboard.Name = "LocationBillboard"
			Billboard.LightInfluence = 0
			Billboard.AlwaysOnTop = true
			Billboard.Size = Logic.LocationImageSize
			Billboard.Adornee = object
			Billboard.PlayerToHideFrom = owner
			Billboard.Active = true

			local Image = Instance.new("ImageLabel", Billboard)
			Image.Name = "LocationImage"
			Image.Size = UDim2.new(1, 0, 1, 0)
			Image.BackgroundTransparency = 1
			Image.Image = "rbxassetid://"..Logic.LocationImage
			Image.ImageColor3 = tcolor

			return Billboard
		end
		return nil
	end

	local function RemoveBillboard(location)
		if location then
			for _, obj in pairs(location:GetDescendants()) do
				if obj:IsA("BillboardGui") and obj.Name:lower() == "locationbillboard" then
					obj:Destroy()
				end
			end
		end
	end

	local function ToggleFlagVisibility(toggle)
		if Logic.FlagHandle and typeof(toggle) == "boolean" then
			Logic.FlagHandle.Transparency = (toggle == true and 0) or 1
			Logic.FlagHandle.Flag.Transparency = (toggle == true and 0) or 1
			Logic.FlagHandle.Flag.Front.Transparency = (toggle == true and 0.7) or 1
			Logic.FlagHandle.Flag.Back.Transparency = (toggle == true and 0.7) or 1
			Logic.FlagHandle.Flag.BillboardGui.ImageLabel.ImageTransparency = (toggle == true and 0) or 1
		end
	end

	local function ClearFlagOwner()
		if Logic.FlagOwner then
			if Logic.FlagOwner then
				ClearFlagObjects(Logic.FlagOwner.Character, Logic.FlagOwner:FindFirstChild("Backpack"))
				RemoveBillboard(Logic.FlagOwner.Character)
				Logic.FlagOwner = nil
			end
			Logic.Dropped = false
			Logic.Captured = false
		end
	end

	local function SetPlayerToFlagOwner(player, character)
		if player and character then
			local FinalParent = (Logic.FlagType:lower() == "accessory" and character) or (Logic.FlagType:lower() == "tool" and player:FindFirstChild("Backpack"))
			if FinalParent then
				Logic.Dropped = false
				Logic.Captured = true
				Logic.FlagOwner = player
				local FlagObject = GiveUserFlagObject(Logic.FlagHandle, Logic.Team, FinalParent)
				if FlagObject then
					FlagObject.Parent = FinalParent
				end
				ToggleFlagVisibility(false)
			else
				warn("FinalParent doesn't exist.")
			end
		end
	end

	local function OnHumanoidDied()
		if Logic.FlagOwner and Logic.FlagOwner.Character and Logic.Captured and Logic.Droppable and Logic.Enabled then
			local HumanoidRoot = Logic.FlagOwner.Character:FindFirstChild("HumanoidRootPart")
			local FloorExists = (HumanoidRoot and DetectFloor(HumanoidRoot.Position + Logic.DropOffset)) or false
			ClearFlagOwner()
			if FloorExists then
				Internal:CreateDrop(HumanoidRoot.Position + Logic.DropOffset)
			else
				ToggleFlagVisibility(true)
			end
		else
			ClearFlagOwner()
			ToggleFlagVisibility(true)
			Internal:Disconnect("TeamChangeConnection")
		end
		Internal:Disconnect("DiedConnection")
	end

	local function OnTeamChanged()
		ClearFlagOwner()
		ToggleFlagVisibility(true)
		Internal:Disconnect("DiedConnection")
		Internal:Disconnect("TeamChangeConnection")
	end

	local function OnFlagHandleTouched(hit, handle)
		if hit and hit.Parent and System.SystemEnabled and Logic.Enabled then
			local HitChar, HitHum, Root = OnFlagHit(Logic, hit)
			local HitPlayer = HitChar and Players:GetPlayerFromCharacter(HitChar)
			if HitPlayer and HitChar and HitHum and Root then
				if HitPlayer.TeamColor ~= Logic.Team.TeamColor or (HitPlayer.TeamColor == Logic.Team.TeamColor and (Logic.DropType:lower() == "teamgrab" or Logic.DropType:lower() == "touchreturn")) then
					if HitPlayer.TeamColor == Logic.Team.TeamColor and Logic.DropType:lower() == "touchreturn" then
						Logic:Reset()
					else
						Internal:Disconnect("DiedConnection")
						Internal:Disconnect("TeamChangeConnection")
						local NewConnection1, NewConnection2 = nil
						SetPlayerToFlagOwner(HitPlayer, HitChar)
						NewConnection1 = HitHum.Died:connect(OnHumanoidDied)
						NewConnection2 = HitPlayer.Changed:connect(OnTeamChanged)
						Internal:EstablishConnection("DiedConnection", NewConnection1)
						Internal:EstablishConnection("TeamChangeConnection", NewConnection2)
						billboard = ApplyLocation(Root, HitPlayer, Logic.Team.TeamColor.Color)
						Logic:OnGrabbed() 
					end
					if handle then handle:Destroy() handle = nil end
				end
			end
		end
	end

	local function OnPadHandleTouched(hit)
		if hit and hit.Parent and Logic.Enabled and System.SystemEnabled then
			local HitChar, HitPlayer = OnPadHit(Logic, hit)
			if HitPlayer and HitChar and HitPlayer.TeamColor == Logic.Team.TeamColor then
				local FlagObject = FindFlagObject(HitChar, HitPlayer:FindFirstChild("Backpack"))
				local OtherTeamInfo = FlagObject and FindTeamInfo(FlagObject:FindFirstChild("TeamOwner"))
				if OtherTeamInfo then
					FlagObject:Destroy()
					OtherTeamInfo:Reset()
					if OtherTeamInfo.Team.TeamColor ~= HitPlayer.TeamColor then
						System:IncreaseScore(HitPlayer, Logic.Team)
						if System.SoundEnabled and Logic.ScoreSound then
							Logic.ScoreSound:Play()
						end
					end
				end
			end
		end
	end

	local function OnPrimaryPartHit(hit)
		if hit then
			local HitPlayer = hit.Parent and Players:GetPlayerFromCharacter(hit.Parent)
			if HitPlayer and HitPlayer.TeamColor ~= Logic.Team.TeamColor then
				OnFlagHandleTouched(hit)
			end
		end
	end

	function Internal:CreateDrop(position)
		if position and Logic.FlagHandle and Logic.Enabled and Logic.Droppable then
			Internal:Disconnect("DiedConnection")
			Internal:Disconnect("TeamChangeConnection")
			if billboard then
				billboard:Destroy()
				billboard = nil
			end
			local NewConnection = nil
			local NewFlag = Logic.FlagHandle:Clone()
			NewFlag.Name = "DroppedFlag"
			NewFlag.Transparency = 0
			NewFlag.Anchored = true
			NewFlag.CFrame = CFrame.new(position)
			NewFlag.Parent = System.DropParent
			NewConnection = NewFlag.Touched:connect(function(hit) OnFlagHandleTouched(hit, NewFlag) end)
			Internal:EstablishConnection("FlagTouched", NewConnection)
			Logic:OnDropped(NewFlag)
		else
			Logic:Reset()
		end
	end

	local function OnPlayerRemoved(player)
		if player and player == Logic.FlagOwner then
			Logic:Reset()
		end
	end

	local function OnRadiusLoop() 
		while Logic.Enabled and Logic.Team and Logic.FlagPad do
			for _, player in pairs(Players:GetPlayers()) do
				if player.TeamColor == Logic.Team.TeamColor then
					local Root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
					if Root and (Root.Position - Logic.FlagPad.Position).magnitude <= Logic.PadRadial then
						OnPadHandleTouched(Root)
					end
				end
			end
			wait()
		end	
	end

	-------------------------------------------------------------------------------------------------------------
	-- Logic Functions / Methods
	-------------------------------------------------------------------------------------------------------------

	function Logic:AddModel(newModel)
		if newModel then
			local NewHandle = (newModel:IsA("Model") and newModel.PrimaryPart) or SearchForFlag(newModel)
			local NewPad = SearchForPad(newModel)
			if NewHandle and NewPad then
				NewHandle.CanCollide = false
				NewHandle.Flag.CanCollide = false
				NewPad.CanCollide = true
				Logic:RemoveModel()
				Logic.FlagModel = newModel
				Logic.FlagHandle = NewHandle
				Logic.FlagPad = NewPad
				local FlagConA = NewHandle.Touched:connect(OnPrimaryPartHit)
				Internal:EstablishConnection("FlagTouchedConnection", FlagConA)
				Logic.Enabled = true
				if Logic.PadBehaviorType:lower() == "touch" then
					local FlagConB = NewPad.Touched:connect(OnPadHandleTouched)
					Internal:EstablishConnection("FlagPadConnection", FlagConB)
				elseif Logic.PadBehaviorType:lower() == "radius" then
					spawn(OnRadiusLoop)
				end
			else
				warn(newModel.Name.." does not have the necessary compontents.")
			end
		end
	end

	function Logic:RemoveModel()
		if Logic.FlagModel then
			Logic:Reset()
			Logic.FlagModel = nil
			Internal:Disconnect("FlagTouchedConnection")
			Internal:Disconnect("FlagPadConnection")
			Logic.Enabled = false
		end
	end

	function Logic:Reset()
		ClearFlagOwner()

		if billboard then
			billboard:Destroy()
			billboard = nil
		end

		ToggleFlagVisibility(true)
		Internal:Disconnect("DiedConnection")
		Internal:Disconnect("TeamChangeConnection")
	end


	function Logic:OnGrabbed()
		print("Grabbed!")
	end

	function Logic:OnDropped(handle)
		if handle then
			print("Dropped!")
			Logic.Dropped = true
			spawn(function() 
				local t = tick() + Logic.ReturnTime
				repeat wait() until t < tick() or handle == nil or Logic.Dropped == false
				if handle and Logic.Dropped then
					handle:Destroy()
					Logic:Reset()
				end
			end)
		end
	end

	-------------------------------------------------------------------------------------------------------------
	-- Finishing Touches
	-------------------------------------------------------------------------------------------------------------

	if flagModel then Logic:AddModel(flagModel) end
	Players.PlayerRemoving:connect(OnPlayerRemoved)
	table.insert(Flags, 1, Logic)
	return Logic
end

function System:FindTeam(teamObject)
	if teamObject and teamObject:IsA("Team") then
		for i = 1, #Flags do
			local Data = Flags[i]
			if Data and Data.Team and Data.Team == teamObject then
				return Data, i
			end
		end
	end
	return nil, nil
end

function System:RemoveTeam(teamObject)
	if teamObject and teamObject:IsA("Team") then
		local Data, Number = System:FindTeam(teamObject)
		if Data and Number then
			Data:RemoveModel()
			Data = nil
			table.remove(Flags, Number)
		end
	end
end

function System:IncreaseScore(player, team)
	print (player,  team)
	if player and team then
		local Data, _ = System:FindTeam(team)
		print(Data, _)
		if System.TeamScoreActive and Data and Data.Score then
			Data.Score.Value = Data.Score.Value + 1
		end
	end
end

function System:SyncData()
	local IgnoreProp = { systemenabled = true, teamscoreactive = true, spectatecolors = true, scorebin = true }
	for i = 1, #Flags do
		local Data = Flags[i]
		if Data then
			for prop, var in pairs(System) do
				if not IgnoreProp[tostring(prop):lower()] then
					Data[prop] = var
				end
			end
		end
	end
end





return System```
1 Like

Shee, that’s a big one lol

I initially thought there might’ve been someone still chilling on a control point so the value kept going up (when to 0 it would be + something right away)
But I see with the captures it’s different indeed

It doesn’t keep printing here after the round, does it?
image

Or that perhaps here it’s something with the StringValue and Numbers interfering
Or possibly a second created value in the Scores folder that is being reset?
image

These are only some thoughts. The other people in here might know more :sweat_smile:

*edit here: I’m offline now. Hopefully these thoughts can help a tiny bit or someone else can help get it resolved >^<

1 Like

I still can’t get it to work :sweat_smile:
Thank you for trying.

I wouldn’t really store the score values in ReplicatedStorage because they are then open to client-side exploitation. They should be put in ServerStorage then changed and checked using remotes. The client can receive the scores for displaying on-screen using RemoteFunctions.

1 Like

Check and see if a script is continually changing the values. I can’t imagine why Roblox would not allow you to change the values.