I’m trying to make a barrage attack for a game I’m scripting for. To achieve this I clone the character using the attack and then remove everything except the parts for the Left/Right arm. It works exactly as I want to it but the issue is that sometimes the arm randomly turns gray.
To isolate this issue, I made the clone slowly delete every part except for the arm. But, for some reason when every other part is destroyed the arm turns gray. Weird thing is that it says in properties that the color of the arm isn’t gray.
The arm that this happens for varies from game to game. Sometimes it’s the left, other times it’s the right. But from what I’ve seen, the arm for which this issue occurs remains the exact same for that playtest.
Here is my script
-- This is a LocalScript inside StarterCharacter
-- Services
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local UIS = game:GetService("UserInputService")
-- Instances
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local function getClone(target,cloneTweenTime)
target.Archivable = true
local clone = target:Clone()
clone.Name = "Clone"
target.Archivable = false
clone.Humanoid.DisplayDistanceType = "None"
local bodyClr = target.UpperTorso.Color
local originalBaseParts = {}
for i,part in pairs(target:GetDescendants()) do
if part:IsA("BasePart") then
originalBaseParts[part.Name] = part
end
end
for i,v in pairs(clone:GetDescendants()) do
-- is the item a decal or a part
if v:IsA("BasePart") or v:IsA("Decal") then
if v.Transparency >= 1 then -- is the item visible? else destroy it
v:Destroy()
else
if v:IsA("BasePart") then -- is the item a part?
-- is the part not a race cosmetic and not an accessory
if not CollectionService:HasTag(v,"raceCosmetic") and not v.Parent:IsA("Accessory") then
v.Anchored = true
end
v.CanCollide = false
if v.Parent == clone then -- if the parent of the part is the clone then it is a body part, thus change the color of it to the clone's color
v.Color = bodyClr
end
end
if cloneTweenTime then
local tween = TweenService:Create(
v,
TweenInfo.new(cloneTweenTime),
{Transparency = 1}
)
tween:Play()
end
end
-- if the item is an attachment or a script then delete it
elseif v:IsA("Attachment") or v:IsA("Script") or v:IsA("ModuleScript") then
v:Destroy()
end
end--]]
if cloneTweenTime then
Debris:AddItem(clone,cloneTweenTime)
end
return clone
end
UIS.InputBegan:Connect(function(input,isTyping)
if input.KeyCode == Enum.KeyCode.R and not isTyping then
local sides = {"Right","Left"}
local chosenSide = sides[math.random(1,2)]
local clone = getClone(char)
clone.Parent = workspace
for _,object in pairs(clone:GetChildren()) do
wait()
if not object:IsA("Humanoid") and not object:IsA("Clothing") and not object:IsA("BodyColors") then
if not table.find({chosenSide.."UpperArm",chosenSide.."LowerArm",chosenSide.."Hand"},object.Name) then
object:Destroy()
end
end
end
end
end)