AFK Script not turning all parts into ForceField

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want everything on the player to change to the ForceField material.

  2. What is the issue?
    Not all of my parts are becoming ForceField material.

Screenshot_9
Screenshot_10

  1. What solutions have you tried so far?
    Modifying BasePart to Part.

Handler Script (In Server Script Service)

local AFKStatus = {}
local AFKEvent = game.ReplicatedStorage:FindFirstChild("AFK")

--[ FUNCTIONS ]--

if not AFKEvent then
	AFKEvent = Instance.new("RemoteEvent")
	AFKEvent.Parent = game.ReplicatedStorage
	AFKEvent.Name = "AFK"
end

local updateAFK = function(player,enable)
	
	local char = player.Character -- character
	local parts = char:GetDescendants() -- get children of the character
	
	if enable then -- if afk
		for i,v in pairs(parts) do
			if v:IsA("Part") then
				v.Material = "ForceField" -- setting parts to forcefield
			end
		end
	else -- if not afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") then
				v.Material = "Plastic" -- setting parts to plastic (original)
			end
		end
	end
	
end

replace if v:IsA(“Part”) then with if v:IsA(“Part”) or v:IsA(“Accessory”) then

1 Like

You need to include accessories in your code, so you need to add v:IsA(“Accessory”)

They are using :GetDescendants()
You will have to use

if v:IsA("Accessory") then
   v.Handle.Material = "ForceField"
end

Tried:

local updateAFK = function(player,enable)
	
	local char = player.Character -- character
	local parts = char:GetDescendants() -- get children of the character
	
	if enable then -- if afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") then
				v.Material = "ForceField" -- setting parts to forcefield
			end
		end
	else -- if not afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") then
				v.Material = "Plastic" -- setting parts to plastic (original)
			end
		end
	end
	

	if enable then -- if afk
		for i,v in pairs(parts) do
			if v:IsA("Accessory") then
				v.Handle.Material = "ForceField" -- setting parts to forcefield
			end
		end
	else -- if not afk
		for i,v in pairs(parts) do
			if v:IsA("Accessory") then
				v.Handle.Material = "Plastic" -- setting parts to plastic (original)
			end
		end
	end
	
end

No change.

Tried:

local updateAFK = function(player,enable)
	
	local char = player.Character -- character
	local parts = char:GetDescendants() -- get children of the character
	
	if enable then -- if afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") or v:IsA("Accessory") then
				v.Material = "ForceField" -- setting parts to forcefield
			end
		end
	else -- if not afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") or v:IsA("Accessory") then
				v.Material = "Plastic" -- setting parts to plastic (original)
			end
		end
	end
	
end

No change.

Remove the :IsA("Accessory") since that will break the script.
Change :IsA("Part") to :IsA("BasePart")

They are already using v:IsA("BasePart")

The script does not break however it still functions the same.

I’m away from my computer so I can’t really test this, but since only accessories are behaving this way, I am guessing it is due to their texture. I don’t know if you can access an accessory’s texture, but if you are able to, then disabling it, putting it’s transparency to 0, or changing it’s parent temporarily might make the accessory default to using the handles material.

Edit: I found this on the DevHub. Maybe the accessories are using a SpecialMesh?

BasePart.Material displays correctly on the mesh when using a MeshPart and not when using a SpecialMesh

Tried adding:

	if enable then -- if afk
		for i,v in pairs(parts) do
			if v:IsA("SpecialMesh") then
				v.MeshId = 9521700421 -- setting parts to forcefield
			end
		end
	else -- if not afk
		for i,v in pairs(parts) do
			if v:IsA("SpecialMesh") then
				v.MeshId = 0 -- setting parts to plastic (original)
			end
		end
	end

Same result.

This causes SpecialMesh parts to have a ForceField material; it doesn’t involve removing accessory textures like @NeptuniaI suggested.

Did you try the code exactly with :IsA("BasePart") instead of :IsA("Part") and without :IsA("Accessory"), like the code below? Maybe try adding print(v.Name) inside the for-loops to see what’s actually being iterated over.

local updateAFK = function(player,enable)
	
	local char = player.Character -- character
	local parts = char:GetDescendants() -- get children of the character
	
	if enable then -- if afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") then
				v.Material = "ForceField" -- setting parts to forcefield
                print(v.Name)
			end
		end
    else -- if not afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") then
				v.Material = "Plastic" -- setting parts to plastic (original)
			end
		end
	end
end
1 Like

That was the code provided in the introduction. It works for everything except accessories.

If anyone is questioning if the script is possible due to Special Meshes, below is an image of the same process in an experience called “Group Recruiting Plaza”.
Screenshot_12

The code you posted initially uses :IsA("Part") when enabling AFK mode. Changing this to :IsA("BasePart") will hopefully solve the issue and give the following result:

https://gyazo.com/5b4a1ea83bc1ea15957b283ba3eaf2cd


local updateAFK = function(player,enable)
	
	local char = player.Character -- character
	local parts = char:GetDescendants() -- get children of the character
	
	if enable then -- if afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") then
				v.Material = "ForceField" -- setting parts to forcefield
			end
		end
	else -- if not afk
		for i,v in pairs(parts) do
			if v:IsA("BasePart") then
				v.Material = "Plastic" -- setting parts to plastic (original)
				print(v.Name)
			end
		end
	end

Results in the same issue.
Screenshot_14

Could you take a screenshot of all of your character’s accessories and all descendants of these accessories?

Edit: I mean from the Explorer

How would you get that information? I don’t see anything like that in my details.
Screenshot_16

The accessories can be found in your character. The character is located in the Workspace. It is named the same as your Roblox handle

Gotcha.

Screenshot_17
Screenshot_18
Screenshot_19