Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Destroying A Part That Destroys the Model?

function armCreation(lArm,rArm)	

	local ArmGroup = workspace:FindFirstChild("ArmGroup")	
	
	parent = lArm.Parent.Name	
	
	arms = ArmGroup[parent]:GetChildren()
	
	for i,v in pairs(arms) do
		v:Destroy()
	end	
	
	fakeLeftArm = lArm:Clone()	
	fakeRightArm = rArm:Clone()
	
	fakeLeftArm.BottomSurface = "Smooth"
	fakeLeftArm.TopSurface = "Smooth"
	
	fakeRightArm.BottomSurface = "Smooth"
	fakeRightArm.TopSurface = "Smooth"
	
	lArm.Transparency = 1
	rArm.Transparency = 1
	
	fakeLeftArm.Name = "fakeLeftArm"
	fakeRightArm.Name = "fakeRightArm"
	
	leftWeld = Instance.new("Weld")
	leftWeld.Name = "leftWeld"
	leftWeld.Parent = fakeLeftArm
	leftWeld.Part0 = fakeLeftArm
	leftWeld.Part1 = lArm
	
	rightWeld = Instance.new("Weld")
	rightWeld.Name = "fakeRightArm"
	rightWeld.Parent = fakeRightArm
	rightWeld.Part0 = fakeRightArm
	rightWeld.Part1 = rArm
	
	fakeLeftArm.Parent = ArmGroup[parent]
	fakeRightArm.Parent = ArmGroup[parent]
	
	
end




game.Players.PlayerAdded:connect(function(player)

    player.CharacterAdded:connect(function(Char)
			
			print("character added")	
	
			player.CharacterAppearanceLoaded:connect(function()
			print("apperance")	
			
			wait(2)
			
			for i,v in pairs(Char:GetChildren()) do
				wait()
				if v:IsA("CharacterMesh") or v:IsA("Shirt") or v:IsA("Pants") or v:IsA("Accessory") then
					v:Destroy()
				elseif v:IsA("BodyColors") then
					
					v.HeadColor = BrickColor.new("Fossil")
					v.RightArmColor = BrickColor.new("Fossil")
					v.LeftArmColor = BrickColor.new("Fossil")
					v.TorsoColor = BrickColor.new("Royal purple")
					v.RightLegColor = BrickColor.new("Dark indigo")
					v.LeftLegColor = BrickColor.new("Dark indigo")
				end	
			end	
				
			armCreation(Char:WaitForChild("Left Arm"),Char:WaitForChild("Right Arm"))
							

		end)
    end)
end)

This code is supposed to give the player visible arms when they join but when they die the armGroup gets destroyed because the arms, for some reason, get destroyed.Can anyone help me prevent this.

2 comments

0

explain it further

0

You should create armGroup every time the character is added. I'll post an answer in a sec.

1 answer

So, I realize that you're trying to make a player's arms visible and that you're having an issue with "armGroup." Although, there's a much simpler solution to making a player's arms visible. Here's what you should do:

First, create a local script and put it inside of the StarterPack. Inside of the script type this:

local Player = game.Players.LocalPlayer -- Gets the player
repeat wait() until Player.Character -- Waits until the player's character is added
local Character = Player.Character -- Gets the player's character
local partsToMakeVisible = {"Left Arm","Right Arm"} -- Creates a table with the name of the things that need to be visible. You can add on to this if you'd like, but the item needs to be inside of the player's character.
local RunService = game:GetService("RunService") -- This gets a service called RunService.

function onRenderStepped()
	for i, v in pairs(Character:GetChildren()) do -- Creates a loop to get the contents of the character.
		for ii, vv in pairs(partsToMakeVisible) do -- Now, it creates a loop that goes through the table above called partsToMakeVisible.
			if v.Name == vv then -- This checks to see if the name of the current item inside of the character is the name of the current item inside of the partsToMakeVisible table.
				if v:IsA("BasePart") then -- Checks to see if the current content's classname is BasePart.
					v.LocalTransparencyModifier = 0 -- If everything is good, and the content is a leftArm or rightArm then it sets it's LocalTransparencyModifier to 0 which makes it visible even when zoomed in.
				end
			end
		end
	end
end

RunService.RenderStepped:connect(onRenderStepped) -- RenderStepped runs every 1/60th of a second. That's incredibly fast. When it runs the function above called onRenderStepped gets called.

I hope I helped, and I tried to explain this as best as possible! I just wanted to help come up with a simpler solution instead of you having to use that long script. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.