--[[
@author TwinPlayzDev_YT
@since 2/15/2021
This script will give the player AFK Overhead GUI When they Tab Out.
--]]
--[ LOCALS ]--
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
local face = char:FindFirstChild("Head")
if enable then -- start
for i,Child in pairs (char:GetChildren()) do
if Child:IsA('MeshPart') then
Child.Material = 'ForceField'
end
end
--
for i,Child in pairs (char:GetChildren()) do
if Child:IsA('Accessory') then
Child:FindFirstChildWhichIsA("MeshPart").Material = 'ForceField'
end
end
else -- stop
for i,Child in pairs (char:GetChildren()) do
if Child:IsA('MeshPart') then
Child.Material = 'Plastic'
end
end
--
for i,Child in pairs (char:GetChildren()) do
if Child:IsA('Accessory') then
Child:FindFirstChildWhichIsA("MeshPart").Material = 'Plastic'
end
end
end
end
AFKEvent.OnServerEvent:Connect(function(player,enable)
AFKStatus[player] = enable
updateAFK(player,enable)
end)
This is a AFK system that I’ve been using in my game, if the player tabs out it turns them into a forcefield ( or whatever is inside the script ) then if they tab in it turns them back to normal.
And pretty much I want to do is make it so when the player parts and meshes n stuff turn into a forcefield they turn into a specific color but then changing the color back to whatever it was before if the player tabs back in
Perhaps you can store the part’s colors in a dictionary table before you change the character’s color? Like when they click, store the original color before the code that changes it.
@MykoNil’s idea will work but if it’s just one color you need to remember you can also just assign it to a variable. But if you need to store multiple do what Myko said.
usually players have their skin color set for their whole body, however others don’t and sometimes they have their head set to black and the rest white or other color, etc, I’ll try doing what Myko said and see if it works, incase yall do find an already made or more simplified version of this do tell, saves me a lot of time ( noobie scripter here lol )
I have not tried this specifically, but I imagine you could get the children of player.Character and iterate through with a for ... in pairs() loop. I.e.: (for index, bodyPart in pairs(player.Character:GetChildren().) Just checking if it’s a UnionOperation or BasePart, or something similar to avoid trying to change a value that doesn’t exist, for example, Color inside of a Humanoid.
you can basically store the BodyColors instance that is in the player character in somewhere before changing it if you didnt know there is an object called BodyColors that is used by humanoids to give them color
then store (set whatever variable = to the color3 object) the entirety of the color3 into the specified dictionary or variable and then when you are ready to fetch it do