You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want everything on the player to change to the ForceField material.
What is the issue?
Not all of my parts are becoming ForceField material.
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
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
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
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
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
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
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”.
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:
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