Gyazo Gif

I'm using SetPrimaryPartCFrame, with a mousefilter set to character(since that seems to be where its happening most). It still flickers like that when its off in the distance. It stops doing it if I adjust it further away, usually, but is not indefinite

--Services
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
--Variables
local isBuilding = false
local selectedPart = nil
local lookingAtPart = nil
local lastPart = nil
local rotate = 0
local maxDistance = 10
--Objects
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local RootPart = player.Character:FindFirstChild("HumanoidRootPart")
local humanoid = player.Character:FindFirstChild("Humanoid")
local mouse = player:GetMouse()
--Misc
local canPlace = Color3.new(50, 200, 50)
local cantPlace = Color3.new(200, 50, 50)
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new()
--Dictionaries
local buildingParts = {
"Floor",
"BackFloor",
"FrontFloor",
"LeftFloor",
"RightFloor",
"BackWall",
"FrontWall",
"LeftWall",
"RightWall",
}


local foundationParts = {
"BackFloor",
"FrontFloor",
"LeftFloor",
"RightFloor",
}


local wallParts = {
"BackWall",
"FrontWall",
"LeftWall",
"RightWall",
}

--Functions
function getMouseTarget()
	local cursorPosition = game:GetService("UserInputService"):GetMouseLocation()
	local oray = game.workspace.CurrentCamera:ViewportPointToRay(cursorPosition.x, cursorPosition.y, 0)
	local ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p,(oray.Direction * 1000))
	return workspace:FindPartOnRay(ray)
end
--
function tableContains(t, value)
    for _, v in pairs(t) do
        if v == value then 
            return true
        end
    end
    return false
end
--
function showParts(model)
	for index, part in pairs(model:GetChildren()) do
		if part.ClassName == "MeshPart" or part.ClassName == "Part" then
			if part.Name ~= "Invis" then
				part.Transparency = 0.5
				part.CanCollide = false
				part.CastShadow = false
				if tableContains(buildingParts, part.Name) then
					part.Transparency = 1
				end		
			end
		end
	end
end

function hideParts(model)
	for index, part in pairs(model:GetChildren()) do
		if part.ClassName == "MeshPart" or part.ClassName == "Part" then
			part.Transparency = 1	
		end
	end
end



-- A sample function providing multiple usage cases for various types of user input
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	
	if not gameProcessed then

		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			print("Left Click")
		elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
			print("Right Click")
		elseif input.KeyCode == Enum.KeyCode.E then
			--Rotate

			if rotate < 360 then
				rotate = rotate+90	
				print("Rotate: "..rotate)
			else
				rotate = 0
				print("Rotate: "..rotate)
			end
			
			
		elseif input.KeyCode == Enum.KeyCode.B then
			--Building Mode

			if isBuilding == false then
				isBuilding = true
				print("Building Mode Enabled.")
			else
				isBuilding = false
				print("Building Mode Disabled.")
				lastPart:Destroy()
				lastPart = nil
				selectedPart = nil
			end
			
		elseif input.KeyCode == Enum.KeyCode.One then
			--Foundation
			if isBuilding then
				if lastPart == nil then
					selectedPart = "Foundation"
					lastPart = game.ReplicatedStorage.Building.Twig_Foundation:Clone()
					lastPart.Parent = workspace
					for index, part in pairs(lastPart:GetChildren()) do
						if part.ClassName == "MeshPart" or part.ClassName == "Part" then
							if part.Name ~= "Invis" then
								part.Transparency = 0.5
								part.CanCollide = false
								part.CastShadow = false
								if tableContains(buildingParts, part.Name) then
									part.Transparency = 1
								end		
							end
						end
					end
				else
					lastPart:Destroy()
					lastPart = nil
					selectedPart = "Foundation"
				end
			else
				--select 1st slot
			end
		elseif input.KeyCode == Enum.KeyCode.Two then
			--Wall
			if isBuilding then
				if lastPart == nil then
					selectedPart = "Wall"
					lastPart = game.ReplicatedStorage.Building.Twig_Wall:Clone()
					lastPart.Parent = workspace
					for index, part in pairs(lastPart:GetChildren()) do
						if part.ClassName == "MeshPart" or part.ClassName == "Part" then
							if part.Name ~= "Invis" or part.Name ~= "Platform" then
								part.Transparency = 0.5
								part.CanCollide = false
								part.CastShadow = false
								if tableContains(buildingParts, part.Name) then
									part.Transparency = 1
								end		
							end
						end
					end
				else
					lastPart:Destroy()
					lastPart = nil
					selectedPart = "Wall"
				end
			else
				--select 2nd slot
			end
		elseif input.KeyCode == Enum.KeyCode.Three then
			--Floor
			if isBuilding then
				if lastPart == nil then
					selectedPart = "Floor"
					lastPart = game.ReplicatedStorage.Building.Twig_Floor:Clone()
					lastPart.Parent = workspace
					for index, part in pairs(lastPart:GetChildren()) do
						if part.ClassName == "MeshPart" or part.ClassName == "Part" then
							if part.Name ~= "Invis" then
								part.Transparency = 0.5
								part.CanCollide = false
								part.CastShadow = false
								if tableContains(buildingParts, part.Name) then
									part.Transparency = 1
								end		
							end
						end
					end
				else
					lastPart:Destroy()
					lastPart = nil
					selectedPart = "Floor"
				end
			else
				--select 3rd slot
			end
		elseif input.KeyCode == Enum.KeyCode.Four then
			
		elseif input.KeyCode == Enum.KeyCode.Five then
			
		elseif input.KeyCode == Enum.KeyCode.Six then
			
		elseif input.KeyCode == Enum.KeyCode.Seven then
			
		elseif input.KeyCode == Enum.KeyCode.Eight then
			
		elseif input.KeyCode == Enum.KeyCode.Nine then
			
		elseif input.KeyCode == Enum.KeyCode.Zero then
			
		end
	end
	
end)


RunService.RenderStepped:Connect(function()
	local part, mousepos = getMouseTarget()
	mouse.TargetFilter = character
	
	if lastPart ~= nil then
		local magni = (lastPart.Invis.Position - character.HumanoidRootPart.Position).magnitude
		
		if magni > maxDistance then
			hideParts(lastPart)
		end
			
		if part == nil then
			hideParts(lastPart)
		else
			showParts(lastPart)
			if selectedPart == "Foundation" then
				if part.Name == "Baseplate" then
					lastPart:SetPrimaryPartCFrame(CFrame.new(Vector3.new(mouse.Hit.X, mouse.Hit.Y+lastPart.Invis.Size.Y/3, mouse.Hit.Z)))
				elseif tableContains(foundationParts, part.Name) then
					lastPart:SetPrimaryPartCFrame(CFrame.new(Vector3.new(part.Position)))
				end
			elseif selectedPart == "Wall" then
				mouse.TargetFilter = lastPart
				
				if part.Name == "Baseplate" then
					lastPart:SetPrimaryPartCFrame(CFrame.new(Vector3.new(mouse.Hit.X, mouse.Hit.Y+lastPart.Invis.Size.Y/3, mouse.Hit.Z)))
				elseif tableContains(wallParts, part.Name) then
					lastPart:SetPrimaryPartCFrame(CFrame.new(Vector3.new(part.Position)))
				end
			elseif selectedPart == "Floor" then
				mouse.TargetFilter = lastPart
				
				if part.Name == "Baseplate" then
					lastPart:SetPrimaryPartCFrame(CFrame.new(Vector3.new(mouse.Hit.X, mouse.Hit.Y+lastPart.Invis.Size.Y/3, mouse.Hit.Z)))
				elseif part.Name == "Floor" then
					lastPart:SetPrimaryPartCFrame(CFrame.new(Vector3.new(part.Position)))
				end
			end
		end
	end
	
end)

1 comment

0

do you know exactly what causes it, when it starts to happen?