My program is meant to be a client sided effect that removes players accessories and makes them neon when a key is pressed, when it is pressed again it reverts them to normal.
I have saved all of the players’ character data into a table that refers to each players accessories and body parts, when I try to loop through the body parts it makes them plastic but only for a very split second, why?
I apologize if there’s a topic on this already, I’ve been searching but I’m not sure if any other cases are my issue also.
Here is the loop
for x, y in charData do
if y:IsA("BasePart") then
y.Material = Enum.Material.Plastic
end
end
Sure thing, I apologize if the readability is poor, I’m not the best at programming in studio
local uis = game:GetService("UserInputService")
local thermalsOn = false
local thermalLighting = Color3.new(1, 1, 1)
local originalLighting = game.Lighting.Ambient
local thermalColor = Color3.new(1, 1, 1)
local originalColor = game.Lighting.ColorCorrection.TintColor
local players = game:GetService("Players")
local char = game.Players
local thisPlayer = game.Players.LocalPlayer
task.wait(2)
local allPlrCharacters = {}--Stores plrName and charData together
local plrName = {} --Stores name of player i.e "Duke_2536" and charData table
local charData = {} --Stores player's Body Parts, Accessories, and Shirts data
uis.InputBegan:Connect(function(input)
if (input.KeyCode == Enum.KeyCode.T) then
if (not thermalsOn) then --Checks if Thermals are currently deactivated
script.Parent.Frame.Visible = true
thermalsOn = true --acts as debounce
game.Lighting.Ambient = thermalLighting --All 3 of these give thermal visuals
game.Lighting.ColorCorrection.Saturation = -1
game.Lighting.ColorCorrection.TintColor = thermalColor
while thermalsOn do
local randomx = (math.random(1, 5) / 10)
local randomy = (math.random(1,5) / 10)
script.Parent.Frame.Grain.TileSize = UDim2.new(randomx, 0, randomy, 0) --Randomly shifts grain texture
task.wait(0.05)
for i, j in pairs(players:GetPlayers()) do
repeat task.wait() until j:HasAppearanceLoaded()
if j.Character.Head.Transparency ~= 1 then --Only inputs data into table for new player if they have not been modified yet
plrName = {} --Prevent duplicates
charData = {}
table.insert(plrName, j.Name)
--Stores all info we need for charData
for z, v in j.Character:GetChildren() do
if v:IsA("BasePart") then
table.insert(charData, v)
end
if v:IsA("Clothing") then
table.insert(charData, v)
end
if v:IsA("Accessory") then
table.insert(charData, v)
end
end
table.insert(plrName, charData)
table.insert(allPlrCharacters, plrName)
print(allPlrCharacters)
end
for k, l in j.Character:GetChildren() do --Sets player's body parts to neon
if l:FindFirstChild("face") then --Checks if face has been destroyed
l.face:Destroy()
local weld = Instance.new("Weld")
local fakeHead = l:Clone()
weld.Parent = l
fakeHead.Parent = l
fakeHead.Position = l.Position
fakeHead.Material = Enum.Material.Neon
weld.Part0 = fakeHead
weld.Part1 = l
l.Transparency = 1 --Sets head to be transparent
end
if l:IsA("BasePart") then
l.Material = Enum.Material.Neon
end
end
j:ClearCharacterAppearance()
end
end
else --Runs if thermals are currently activated
for x, y in charData do
if y:IsA("BasePart") then
y.Material = Enum.Material.Plastic
end
end
--Reverts back to normal visuals
game.Lighting.Ambient = originalLighting
game.Lighting.ColorCorrection.TintColor = originalColor
game.Lighting.ColorCorrection.Saturation = 0
script.Parent.Frame.Visible = false
thermalsOn = false
end
end
end)
Sorry for the VERY late response,
One problem is that you’re constantly updating the player’s model in a while loop.
Another problem is that you’re updating the players model when turning thermals off before you actually set the thermalsOn variable to false which doesn’t stop the while loop for enough time that the while loop would reset the players model to Neon.
You also aren’t re-adding accessories.
Now I can see the reason you would have a while loop for thermals being on.
Instead of using a while loop, use PlayerAdded and CharacterAdded events that check when thermals are on and if they are update the player’s character to be Neon.
Don’t worry I appreciate the reply regardless, thank you for the info by the way.
Also I was aware of the accessories not being added, my idea was to simply start with making sure I can reset the skin, but thank you for the advice on the loop. Had a feeling it wasn’t well optimized.