What could be causing this sort of visual bug?

I’ve scripted a fairly standard raid system, but approximately 20% of the time when I activate it, a weird visual glitch occurs. It’s worth noting this only happens in game not in play mode and causes no error text in the console, so I genuinely have no clue where to start.

Expected:

Glitch:


While my code does iterate over the parts in the models that are glitched out (via collectionservice and tags), none of my code has any effect on the baseplate.

If anyone knows what quirks of how roblox works might be causing it, help would be appreciated. I just genuinely have no clue what it could even be to start debugging or fixing it. Or if this is some roblox bug that is known and/or needs reported.

Other bits of info that might be useful:
Only the visuals are glitched, glitched out parts still have normal collision boxes.
I’m not adjusting any part data in localscripts, only in server scripts.
The visual glitches only appear after the raid system is started, spawning in everything is normal, so it’s something in the actual script causing it.
In Test mode, mousing over visually glitched objects with select reverts them to their proper form.

I’ve tried toggling off various parts of the relevant scripts, but it’s difficult to tell if it has any effect since the chances of the glitch happening are annoyingly low.

Yeah the same thing has happened to me before. It just went away for me. Might just be on roblox’s end and has nothing to do with your code

are you getting a bug where it would flash in and out quickly and your character would be weird to move around?

i had this happen to me before and it was caused by having parts from PartCache being too far away when teleported in to be used

Pretty sure it’s at least related to my code from the behavior that’s happening. I’ve been brute-force commenting out sections and testing them, which due to the unreliable nature of the visual glitch has taken a while. Based on what bits I have commented out with it working, my current running theory is I’m either calling :GetAttribute, :SetAttribute, or :GetAttributeChangedSignal too quickly (or all three) and it’s breaking things. Which, well, is very confusing for a variety of reasons starting with the obvious fact it shouldn’t cause a visual bug that affects random parts.

Character moves normally, some weird part flashes happen depending on camera angle. (see gif in original post) I don’t teleport the player at any point so I doubt this is it, though the input is appreciated anyways.

could you show the code to see what could be causing it

Frankly I’m not sure it’ll help at this point, but sure. Here’s the relevant snippet.

Commented out parts are the bits that seem to be causing the issue. TermMain is launched via a coroutine wrap later in the code and the Term variable is a model in workspace, with a part named “Core” inside it. All called/set attributes are created before any of this code fires.

local Replicated = game:GetService("ReplicatedStorage")
local GameSettings = require(Replicated.RAID_ReplicatedStorage.GameSettings)
local Variables = Replicated.RAID_ReplicatedStorage.Variables
local PlayerService = game:GetService("Players")

local function GetPlayersWithinRadius(Position, Radius, PlayerList)
	PlayerList = PlayerService:GetPlayers()
	local PlayersFound = {}
	for PlayerIndex, Player in next, PlayerList do
		if Player.Character then
			if Player.Character:FindFirstChild("HumanoidRootPart") then
				if (Player.Character.HumanoidRootPart.Position - Position).magnitude <= Radius then
					table.insert(PlayersFound, Player)
				end
			else
				warn(Player.Name .. " does not have a HumanoidRootPart and cannot be checked for Position\n" .. debug.traceback())
			end
		else
			warn(Player.Name .. " does not have a character and cannot be checked for Position\n" .. debug.traceback())
		end
	end

	return PlayersFound
end

local function TermMain(Term)
	local ImperialEarn = 0
	local RebelEearn = 0
	while Variables.ProgressVars:GetAttribute(Term.Name.."Active") ~= (nil or false) do
		if Variables.ProgressVars:GetAttribute("RaidStatus") == "On" then
			local ImperialsIn = 0
			local RebelsIn = 0
			local playerTable = GetPlayersWithinRadius(Term.Core.Position, GameSettings.CapturePoint.CaptureRadius)
			for _, player in next, playerTable do
				if player.Character:FindFirstChild("Humanoid").Health > 0 then
					for _, Name in pairs(GameSettings.Teams.Imperial) do
						if player.TeamColor == game.Teams[Name].TeamColor then
							ImperialsIn = ImperialsIn + 1
						end
					end
					for _, Name in pairs(GameSettings.Teams.Rebel) do
						if player.TeamColor == game.Teams[Name].TeamColor then
							RebelsIn = RebelsIn + 1
						end
					end
				end
			end
			local Tick = 1 / (GameSettings.CapturePoint.TimeToCapture / 2)
			local CurPercent = Variables.ProgressVars:GetAttribute(Term.Name.."Percent")
			if ImperialsIn > RebelsIn then
				if CurPercent < 1 then
					--Variables.ProgressVars:SetAttribute(Term.Name.."Percent", CurPercent+Tick)
					if CurPercent+Tick >= 1 then
						--Variables.ProgressVars:SetAttribute(Term.Name.."Owner", "Imperial")
						ImperialEarn = ImperialEarn + GameSettings.CapturePoint.PointsAmount
						--Variables.ProgressVars:SetAttribute("ImperialGrowth", Variables.ProgressVars:GetAttribute("ImperialGrowth") + ImperialEarn)
					end
					if CurPercent < 0 and CurPercent+Tick >= 0 then
						--Variables.ProgressVars:SetAttribute(Term.Name.."Owner", "Neutral")
						--Variables.ProgressVars:SetAttribute("RebelGrowth", Variables.ProgressVars:GetAttribute("RebelGrowth") - RebelEearn)
						RebelEearn = RebelEearn - GameSettings.CapturePoint.PointsAmount
					end
				else
					if ImperialEarn == 0 then
						ImperialEarn = ImperialEarn + GameSettings.CapturePoint.PointsAmount
						--Variables.ProgressVars:SetAttribute("ImperialGrowth", Variables.ProgressVars:GetAttribute("ImperialGrowth") + ImperialEarn)
					end
				end
			elseif RebelsIn > ImperialsIn then
				if CurPercent > -1 then
					--Variables.ProgressVars:SetAttribute(Term.Name.."Percent", CurPercent-Tick)
					if CurPercent-Tick <= -1 then
						--Variables.ProgressVars:SetAttribute(Term.Name.."Owner", "Rebel")
						RebelEearn = RebelEearn + GameSettings.CapturePoint.PointsAmount
						--Variables.ProgressVars:SetAttribute("RebelGrowth", Variables.ProgressVars:GetAttribute("RebelGrowth") + RebelEearn)
					end
					if CurPercent > 0 and CurPercent-Tick <= 0 then
						--Variables.ProgressVars:SetAttribute(Term.Name.."Owner", "Neutral")
						--Variables.ProgressVars:SetAttribute("ImperialGrowth", Variables.ProgressVars:GetAttribute("ImperialGrowth") - ImperialEarn)
						ImperialEarn = ImperialEarn - GameSettings.CapturePoint.PointsAmount
					end
				else
					if RebelEearn == 0 then
						RebelEearn = RebelEearn + GameSettings.CapturePoint.PointsAmount
						--Variables.ProgressVars:SetAttribute("ImperialGrowth", Variables.ProgressVars:GetAttribute("RebelGrowth") + RebelEearn)
					end
				end
			end
		end
		task.wait(1)
	end
	--Variables.ProgressVars:SetAttribute("ImperialGrowth", Variables.ProgressVars:GetAttribute("ImperialGrowth") - ImperialEarn)
	--Variables.ProgressVars:SetAttribute("RebelGrowth", Variables.ProgressVars:GetAttribute("RebelGrowth") - RebelEearn)
end

i suggest you turn the attributes into values if you are going to update them alot. attributes arent updated so much, using a value will prevent you from constantly calling a function and running whatever code it required to get it

also just using variables would work too

Yeah, the issue appears to be rapidly updating attributes.

I can’t figure out any way to repro my own issue in any other code, I’ve already tried a few different things, so I’m not really able to make a bug report, so… mark it as solved I guess?